Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why does localplayer appear nil when i test it out?

Asked by 6 years ago

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

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

0
You're using a localscript, right? MrBlockyhead 84 — 6y
0
It needs to be in a LocalScript in game.StarterPlayer.StarterPlayerScripts or game.StarterPack SebbyTheGODKid 198 — 6y
0
wont work faze_spas 0 — 6y
0
Be more clear, and give a short example of the code. GoldenCosmo 64 — 6y
0
Try repeat wait() until game.Players.LocalPlayer.Character without the ~= nil Simnico99 206 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.
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. ee0w 458 — 6y
Ad

Answer this question