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

Why do I get an error saying Player is nil?

Asked by 9 years ago

In a script I made located in the PlayerGui, It is a Server Sided script btw.

I use this code.

local Player = game.Players.LocalPlayer; -- Line 1
repeat wait() until Player.Character ~= nil --Line 2
local Character = Player.Character --Line 3

The error happens on Line 2, this is a script that works with a Credit GUI. Just for like buying credits for a game of mine via Developer Products.

1 answer

Log in to vote
1
Answered by 9 years ago

Well first off, You should check the Wiki located at Wiki.Roblox.Com, they have most of the answers there. So check that out first next time.

But the main problem in your code is that you are using a Server Sided script. 'game.Players.LocalPlayer', only works in Local Scripts. Try using a local script and see if that will fix the problem.

Ad

Answer this question