local player = game.Players.LocalPlayer
game.Players.PlayerAdded:connect(function(player)
local Age = player.leaderstats.Age
if Age == 0 then
script.Parent.Visible = true
end
end)
I kinda want it to check if the Leaderstats is Zero, then open a GUI Frame if it is.
And this one I want to add to the stats
(Script is normal script)
script.Parent.MouseButton1Click:connect(function()
local player = game.Players.LocalPlayer
player.leaderstats.Age.Value = player.leaderstats.Age.Value + 10
script.Parent.Parent.Visible = false
end)
On this line, you use if Age == 0 then, but that just checks if the variable is 0, which it isnt. You’ll want to change this to check the value instead, since that’s what actually holds the data: if Age.Value == 0 then
PlayerAdded will not be fired because the player is added before the localscripts are created.
And, changing these values on the client-side will not replicate to the server.
Basically, the server will not see that chance, nor will any other players within the game.
Use a server-script instead if you’re going to implement a saving system or want others to see the value.
Here’s a simple script (server-script) that will help you out.
local Players = game:GetService('Players')
local function PlayerAdded(Player)
-- Code
end
local GetPlayers = Players:GetPlayers()
for i = 1, #GetPlayers do
local Target = GetPlayers[i]
coroutine.resume(coroutine.create(function()
PlayerAdded(Target)
-- Run this function for each player in parralell.
-- In rare cases, the player is added before the event is able to pick it up.
end))
end
Players.PlayerAdded:Connect(PlayerAdded)