What i am trying to achieve:
In this script I am trying to spawn a part on the Cframe of the characters HumanoidRootPart
The problem: Keep getting an error message I dont know how to fix. "Players.snipperdiaper.Backpack.Tool.LocalScript:4: attempt to index nil with 'WaitForChild'"
Anyone know why this keeps happening?
Line in question:
humanoidRootPart = character:WaitForChild("HumanoidRootPart")
Complete Script (Not finished with the CFrame spawning yet)
local tool = script.Parent player = game.Players.LocalPlayer character = game.Players.LocalPlayer.Character humanoid = character:WaitForChild("Humanoid") humanoidRootPart = character:WaitForChild("HumanoidRootPart") tool.Activated:Connect(function() local part = game.Workspace:FindFirstChild("BariWall") local ClonedPart = part:Clone() part.Parent = workspace end)
always put local before each variable and change the character variable to this:
local tool = script.Parent local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid") local humanoidRootPart = character:WaitForChild("HumanoidRootPart") tool.Activated:Connect(function() local part = game.Workspace:FindFirstChild("BariWall") local ClonedPart = part:Clone() part.Parent = workspace end)
I hope it helps ^^