i keep trying repeat wait() until game.Players.LocalPlayer.Character ~= nil
but it keeps saying localplayer is nil. I need help badly.
i keep trying repeat wait() until game.Players.LocalPlayer.Character ~= nil
but it keeps saying localplayer is nil. I need help badly.
You need to use a LocalScript. Regular scripts run on the server, and therefore don't have any LocalPlayer. Depending on what the script is used for, there are multiple suggestions on where to place your LocalScript.
-- local script in Replicated First (as an example)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
-- ^^ this will wait for the character to load.
Adding on to what he said, when running a Test Server in Studio, the server and the client are conjoined. Because of this, the server has a LocalPlayer (which is always Player1.) This is why it's better to load a Local Server rather than one directly in Studio.
This discussion is preserved as it was. New answers, comments, and votes are closed.
5 comments
You're using a localscript, right?
It needs to be in a LocalScript in game.StarterPlayer.StarterPlayerScripts or game.StarterPack
wont work
Be more clear, and give a short example of the code.
Try repeat wait() until game.Players.LocalPlayer.Character without the ~= nil