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

'Attempt to index nil with leaderstats' Why is this and is there a better way to access a player?

local textLabel = script.Parent

textLabel.Text = game:GetService("Players").LocalPlayer.leaderstats.Points.Value

for context I have a leaderstats script that creates a folder named leaderstats in any player in the game with the points value inside it and what I am trying to do is have the number of points displayed of a gui, is there a simple fix, or is there a better way to about this?

3 comments

0

You can't get the local player in a server script

0

Try putting a wait script between the first line and the third line.

0

put this is a while true loop. it will update

2 answers

✓ Accepted answer

Your problem (most likely) is the fact that you are using a server script, and the problem in that is, you can't get the player through that.

Make it a local script and then use WaitForChild on leaderstats. eg :

local textLabel = script.Parent

textLabel.Text = game:GetService("Players").LocalPlayer:WaitForChild('leaderstats').Points.Value

1 comment

0

it will not update, it just stays at whatever it was first when it loaded in

I think you have to put it in a while true loop to update the text every time.

local textLabel = script.Parent

while true do 
textLabel.Text = 		game:GetService("Players").LocalPlayer:WaitForChild('leaderstats').Points.Value [[-- It is good to add a WaitForChild so it only loads in when the leaderstats is found --]]
wait(1) -- Waits one second before reloading
end

5 comments

0

Thank you sm

0

please mark it as answered!

0

please mark it as answered!

0

please mark it as answered!

0

No, please don't use a while loop for this, use GetPropertyChangedSignal.

This discussion is preserved as it was. New answers, comments, and votes are closed.