✓ Accepted answer
The Character of a player loads in a little bit after the player object itself loads, and thus when the localScript first loads, the Character is nil. A common way to get around this is to use the following code:
local char = player.Character or player.CharacterAdded:wait()
With the or in there, when running this script, the game will first check if player.Character is a thing, and if it is, will return player.Character, however, if player.Character is not a thing yet (hasn't loaded yet) it will run player.CharacterAdded:wait() and wait for the character before returning it.
Since you didn't specify in your question, I assumed you used a LocalScript, if you used a ServerScript then you can't use LocalPlayer, because it will return nil instead of a player object. This occurs because there is one server, and many clients. LocalScripts are run on the client, which let's you use LocalPlayer, however, ServerScripts (obviously) run on the server, and don't have a LocalPlayer to reference.
This works when using solo play, because (at least I don't think) studio doesn't run a server in the background while you play as the client. Although, I believe studio does recognize some things that shouldn't be, as, in my experience, LocalScripts do not run in the workspace during solo play, which is how they should work.
1 comment
So yea, I had everything in a server script instead of a local script. However, I found a much easier way to do this. I can just say script.Parent.Parent to get the character holding my tool. Thanks for setting me straight on local/server scripts.