I wrote a script, but it’s giving me this error:
Can someone please explain to me what this error is and what it means? I would really appreciate it!
I wrote a script, but it’s giving me this error:
Can someone please explain to me what this error is and what it means? I would really appreciate it!
It means you’re trying to use :WaitForChild()
on a nil
value somewhere in your code.
But, I’m not using it on a nil instance, I’m using it to wait for the humanoid root part of a character.
Can you show us the part where you declare the LocalPlayerCharacter
variable? You’re probably trying to declare the LocalPlayerCharacter
before the game even adds the character to workspace.
That probably means that the Character does not exist yet.
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait() -- waits for the character to load if it doesn't exist
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
LocalPlayer.CharacterAdded:Connect()
will not yield your code to wait for the character, you should use local LocalPlayerCharacter = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
instead.
Oh I just do:
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local HRP = player.Character.HumanoidRootPart
Can you show me the location of the local script?
I tried it and it worked! Thank you so much for your help!