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

Leaderstats isn't being recognised by script?

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

✓ Accepted answer

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)

2 comments

0

Thanks!

0

Thank you so much! I have been searching everywhere for this!

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

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

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