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

Script not recognizing leaderstats?

Asked by
zomspi 541 Moderation Voter
5 years ago

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!

0
Dude snowwyyyyy2 30 — 5y
0
Don't store leaderstats on the client ForeverBrown 356 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

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)

0
Unfortunately that doesn't work, I get no error messages or anything. Just, nothing? zomspi 541 — 5y
0
I'd recommend using remote events/functions...that solution could still run into problems. ForeverBrown 356 — 5y
0
StarterGui Service is serversided, you want PlayerGui. vkax 85 — 5y
Ad
Log in to vote
0
Answered by
vkax 85
5 years ago

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 :)

0
Also sorry for the formatting, I'm on a chromebook at school. vkax 85 — 5y
0
That still doesn't work? Do I need to use remote events or something? zomspi 541 — 5y

Answer this question