Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with EgoMoose's FPS gun visuals tutorial?

Asked by
o_Blyzo 12
4 years ago

Sorry if this isn't the right place, please guide me elsewhere if that's the case.

I'm following EgoMoose's first person shooter gun tutorial and I've gotten up to the part where the weapon is being attached to the viewmodel. My gun and viewmodels are in Replicated Storage, and the viewmodel is being properly rendered.

However, for some reason, rather than the script actually rendering the gun onto the screen (like it should do, as seen in the tutorial), it simply spawns the gun in Workspace instead, which isn't what I'm intending to happen.

Could anyone help with this? I've definitely followed all parts of the tutorial, including adding the required Handles to the gun and other stuff, however nothing I do seems to be working and it's quite frustrating.

Here's the script, which is placed in StarterPlayerScripts, for reference:

local camera = game.Workspace.CurrentCamera
local humanoid = game.Players.LocalPlayer.CharacterAdded:Wait():WaitForChild("Humanoid")

local viewModel = game.ReplicatedStorage:WaitForChild("viewModel"):Clone()

local function onDied()
    viewModel.Parent = nil
end

local function onUpdate(dt)
    viewModel.Head.CFrame = camera.CFrame
end

humanoid.Died:Connect(onDied)
game:GetService("RunService").RenderStepped:Connect(onUpdate)

local repWeapon = game.ReplicatedStorage:WaitForChild("testGun")
local weapon = repWeapon:Clone()

weapon.Parent = viewModel
viewModel.Parent = camera

local joint = Instance.new("Motor6D")
joint.C0 = CFrame.new(0, 0, 0) -- temporary
joint.Part0 = viewModel.Head
joint.Part1 = weapon.Handle
joint.Parent = viewModel.Head

Answer this question