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)

7 comments
What type of script this is exactly? Server-side or Client-side?
It's client-sided
First off, the character is not guaranteed to have loaded. You'll need to set up logic to wait until it does if need be. Assuming this LocalScript is a descendant of StarterPack, you'll need to take extra steps to ensure you're accessing the latest character.
See the bottom of the following link for more information: https://developer.roblox.com/en-us/api-reference/property/Player/Character
Secondly, since you're using a LocalScript, the creation of your BariWall clone will not be replicated. This is fine for VFX, but you'll still need to contact the server so it may instruct other clients to raise the same wall.
P.S. You're using FindFirstChild inappropriately. You should barely find yourself using its return value without checking it beforehand, if not at all. Its overall prescense isn't warranted, too. I also don't see a good reason for BariWall to rest in Workspace. ReplicatedStorage seems more appropriate.
Please post on the answer section instead of the comment section if you are posting an answer/explanation and not a simple question or stuff.