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

Script not recognizing leaderstats?

My local script isn't recognizing my leaderstats value? My script is:

Local Script

game.Players.PlayerAdded:connect(function()
	if game.Players.LocalPlayer.leaderstats.Purchases.Value == 1 then
		print("Hi")
		game.StarterGui.ScreenGui.Frame1.Desert.Visible = true
	else
		game.StarterGui.ScreenGui.Frame1.Desert.Visible = false
end
end)



Thanks!

2 comments

0

Dude

0

Don't store leaderstats on the client

2 answers

The script is wrong. You are using a when a player joins, since the server executes the server scripts first, leaderstats may or not been made. Solution:

--\\Client
local player = game:GetService("Player").LocalPlayer
--\\Services
local rs = game:GetService("ReplicatedStorage")
local gsg = game:GetService("StarterGui")
    if player.leaderstats.Purchases.Value == 1 then
        print("Hi")
        gsg.ScreenGui.Frame1.Desert.Visible = true
    else
        gsg.ScreenGui.Frame1.Desert.Visible = false
end
end)

3 comments

0

Unfortunately that doesn't work, I get no error messages or anything. Just, nothing?

0

I'd recommend using remote events/functions...that solution could still run into problems.

0

StarterGui Service is serversided, you want PlayerGui.

Hello! Hope I'm here to answer your question. Your script is incorrect because game.Players.PlayerAdded is a server sided event The correct script would be

	    if game.Players.LocalPlayer:WaitForChild("leaderstats").Purchases.Value == 1 then
	        print("Hi")
	        game.StarterGui.ScreenGui.Frame1.Desert.Visible = true
	    else
	        game.StarterGui.ScreenGui.Frame1.Desert.Visible = false
	end

Wait before you check :)

2 comments

0

Also sorry for the formatting, I'm on a chromebook at school.

0

That still doesn't work? Do I need to use remote events or something?

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