#help with updating gems count

4 messages · Page 1 of 1 (latest)

tranquil scaffold
#

i have a system that updates the gem count periodically.. i also have a skip stage button that deducts some amount of gems .. but afte the deduction , the gems increment from the value before it was deducted.. hopefully u get it

#

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