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

Leaderstats isn't being recognised by script?

Asked by
zomspi 541 Moderation Voter
5 years ago
Edited 5 years ago

My leaderstats value isn't being recognised by a local script. I have had many attempts with this script but none have worked, here is my 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)

This is what it looks like: https://ibb.co/0MmHShY and this is what it's supposed to look like: https://ibb.co/NYRpngM Thanks if anyone can help!

3 answers

Log in to vote
0
Answered by
TopBagon 109
5 years ago
Edited 5 years ago

Sorry for the late answer

Make sure you put this in a local script (inside the desert button)

local purchases = game.Players.LocalPlayer.leaderstats.Purchases

purchases.Changed:Connect(function()
    if purchases.Value == 1 then
        print("Hi")
        script.Parent.Visible = true
    else
        print("Bye")
        script.Parent.Visible = false
    end
end)

when the script runs it checks instantly and since it's 0 at the beginning it makes the visible false and ignores any changes after that (unless you manually write that down as I did above)

0
Thanks! zomspi 541 — 5y
0
Thank you so much! I have been searching everywhere for this! zomspi 541 — 5y
Ad
Log in to vote
0
Answered by
karlo_tr10 1233 Moderation Voter
5 years ago
Edited 5 years ago

It may not be problem in recognation, this script would run once to check if that value is true or false. You should wrap that if statement in signal changed event or while true loop:

Instance:GetPropertyChangedSignal("Value"):Connect(function()

Or
While true do

wait(what you want)
end

Log in to vote
0
Answered by
zomspi 541 Moderation Voter
5 years ago

I'm sorry I don't really understand, where would I put my script in this script and how should I tell it what leaderstat? Thanks!

Instance:GetPropertyChangedSignal("Value"):Connect(function()



Or

While true do



wait(1)

end

Answer this question