while wait(1) do
for i, Player in pairs(game.Players:GetPlayers()) do
-- We are looping through every player in game
-- We now have to check if the player actually has leaderstats loaded to prevent errors
if Player:FindFirstChild("leaderstats") and Player.leaderstats:FindFirstChild("coins") then
Player.leaderstats.coins.Value+=1 -- Increase The Coin Value By 1
end
end
end
Your while loop should look like this.
Amazing! Thank you so much for your help!
1 Like
Another approach:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local coins = Instance.new("IntValue", leaderstats)
coins.Name = "coins"
leaderstats.Parent = player
while task.wait(1) do
if not coins then break end
coins.Value += 1
end
end)