So I'm having an issue right now creating a tool. This message popped out when I played in online mode. The error comes from line 3. Do you know how to fix it?

Btw, it is a localscript


local t = script.Parent
local player = game.Players.LocalPlayer.Character
local torso = player:WaitForChild("Torso")


6 comments

0

probably you should wait for the character to load

0

There's a WaitForChild at the third line, so I don't think thats the issue

0

but it uses the variable to get the torso though

0

It is the issue. Define the player in one line (using just local player = game.Players.LocalPlayer) and then the character in the next (using player.Character or player.CharacterAdded:Wait()). This way, the script will wait for the character to load.

0

Or, you can actually just do it in one line like so: local player = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait(). I would opt for the first option though as the player variable will most likely come in handy later and that way you can have a variable for both the player and the character.

0

My tool works now. Thanks alot guys