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

ServerScriptService.Script:1: attempt to index field 'LocalPlayer' (a nil value) what do i do?

Asked by
sproxa 7
6 years ago

Im trying to make a gui that appears after 3 secs when a gui is opened but it always says " ServerScriptService.Script:1: attempt to index field 'LocalPlayer' (a nil value)"

Here is the script i used

if game.Players.LocalPlayer.PlayerGui.ScreenGui3.ImageLabel.Visible == true

 then 
wait(3)
game.Players.LocalPlayer.PlayerGui.ScreenGui4.Frame.Visible = true


It is my first script i made by myself so i was sure there was gonna be a problem
0
LocalPlayer is nil on the server. User#19524 175 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

From ScriptingHelpers common mistakes:

LocalPlayers and Server Scripts

This is one of the most common issues seen on the site. A beginner may use LocalPlayer trying to find the desired player in the game when they come to find out that LocalPlayer is a nil value. At this point, we may conclude the script writer is using a Server Script. The difference between Server Scripts and Local Scripts is that Server scripts act on behalf of the server. The server is what is connecting all the players together. It's a physical server found at Roblox Headquarters that bring you the content of the game. Local Scripts will act on behalf of the Client, that being you and your computer, the intended target.

Think of it like your house and room. Your room is your room, you're the only person in your room. So for the Local Script, your Local Script is your Local Script, it works for you. However your house is your house, but everyone else is living in it. Your parents, siblings, and possibly other family members or pets. A Server Script would be acting for your house since it's acting for several people it can not keep track of that one intended person being LocalPlayer. To make things easy for the server LocalPlayer is nil to the server.

Fortunately, ROBLOX accounts for most of the events and instances you would need to get the Player in a Server Script. Some events would include PlayerAdded, Touched, or MouseClick. You would have to figure out your way of getting the player. http://www.scriptinghelpers.org/blog/common-mistakes

Ad

Answer this question