#help with updating gems count
4 messages · Page 1 of 1 (latest)
game.Players.PlayerAdded:Connect(function(plr)
-- Create leaderstats folder
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
-- Create Stage value
local stage = Instance.new("IntValue", leaderstats)
stage.Name = "Stage"
stage.Value = 1
-- Create Gems value
local gems = Instance.new("IntValue", leaderstats)
gems.Name = "Gems"
gems.Value = 0
-- Gem increment every 5 seconds
local function incrementGems()
while true do
wait(5) -- Wait 5 seconds before increasing
if not plr:FindFirstChild("leaderstats") then return end -- Stop if player leaves
-- Increment gems if manual deduction is not in progress
if gems then
gems.Value = gems.Value + 1
end
end
end
-- Start the gem increment function in the background
spawn(incrementGems)
end)
this is the leaderstat script