My local script to see the value of leaderstat isn't working. Do I need to make it server script with remote events? Here is my 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!
This is the code you wrote:
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)
Let us make some fixes!
The only fix that is needed is the game.StarterGui.ScreenGui.Frame1.Desert.Visible
and also game.Players.PlayerAdded
if you want this to check whenever the player gets 1 purchase.
This usually is never used, instead, use this:
I'm gonna make a variable to shorten the game.Players.LocalPlayer
.
local player = game.Players.LocalPlayer player.PlayerGui.StarterGui.ScreenGui.Frame1.Desert.Visible =
Now with our fixed code the final code should be:
local player = game.Players.LocalPlayer game.Players.PlayerAdded:Connect(function() -- You could just use a while wait(.1) but that is inefficient. Although this is when the player joins it checks the following code. if player.leaderstats.Purchases.Value == 1 then print("Hi") player.PlayerGui.StarterGui.ScreenGui.Frame1.Desert.Visible = true else player.PlayerGui.StarterGui.ScreenGui.Frame1.Desert.Visible = false end end)
If you have any more questions please feel free to comment more than happy to help:)