local players = game:GetService("Players")
local player = players.LocalPlayer
local char = player.Character
local torso = char:WaitForChild("torso")
the script is inside of starterplayerscripts and is a local script
and this is how my explorer looks like:
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
yes i searched on the dev forum and the developer hub, just the same as normal. the weird thing is that i am using :WaitForChild() for a pretty decent time now but i just can’t seem to figure it out.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
If you had x:Method(), and you get an error "attempt to index nil with Method", this loudly means x is nil.
In your case you’re doing char:WaitForChild("Torso"), you got the error which means when the script ran, char, or the player.Character, was nil. This is because it didn’t load yet. Generally, local scripts that are parented outside of the character will run first, and there is a chance they might run before the character has loaded.
To circumvent this, you need to wait for the character itself to load first. You logically can’t wait for something to load (the Torso) when you’re not sure if its parent (the character) has even loaded. Waiting for the character is a common idiom in Roblox, that you’ll commonly see written this way.
local char = player.Character or player.CharacterAdded:Wait()
What this is saying, if the character, luckily, already loaded, it will just use it without waiting for it to load (in this case it uses player.Character), else if it hasn’t loaded, it will pick wait for it to load using this player.CharacterAdded:Wait(). Explaining what the or is doing, and what even is player.CharacterAdded:Wait() are a rabbit role that I’m sure is gonna confuse you, so let’s not mention it, but I’m happy to explain them if you’re interested.