RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"make a viewmodel script for a first person shooter"
-- Local Script in StarterPlayerScripts local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Camera = workspace.CurrentCamera local Tool = script.Parent local GunModel = Tool.GunModel local function updatePosition() local ray = Camera:ScreenPointToRay(Mouse.X, Mouse.Y) local position = ray.Origin + ray.Direction * 5 GunModel:SetPrimaryPartCFrame(CFrame.new(position, position + ray.Direction)) end local function onEquipped() GunModel.Parent = workspace GunModel:SetPrimaryPartCFrame(CFrame.new(Camera.CFrame.p, Camera.CFrame.p + Camera.CFrame.lookVector)) updatePosition() Mouse.Move:Connect(updatePosition) end local function onUnequipped() GunModel.Parent = Tool GunModel:SetPrimaryPartCFrame(CFrame.new()) end Tool.Equipped:Connect(onEquipped) Tool.Unequipped:Connect(onUnequipped)