Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why does localplayer appear nil when i test it out?

i keep trying repeat wait() until game.Players.LocalPlayer.Character ~= nil

but it keeps saying localplayer is nil. I need help badly.

5 comments

0

You're using a localscript, right?

0

It needs to be in a LocalScript in game.StarterPlayer.StarterPlayerScripts or game.StarterPack

0

wont work

0

Be more clear, and give a short example of the code.

0

Try repeat wait() until game.Players.LocalPlayer.Character without the ~= nil

1 answer

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 Scripts can run in:

  • Replicated First
  • Inside players' characters
  • Anywhere inside the Player
-- 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.

1 comment

0

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.