What do I want to achieve?
I’m trying to attach an FPS viewmodel to a player’s camera.
What is the issue?
My script that is meant to attach the viewmodel to the camera is not working properly, or that’s at least what I’m assuming.
What solutions have I tried so far?
I have tried rewriting my code, different viewmodels, placing my script in different places, changing my script from LocalScript to Script, and getting help from a fellow dev.
My script (this is the only script – LocalScript – in the game so far, it’s in the StarterCharacterScripts):
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);
Setup:
Result:
Output (no errors):
Thanks in advance.