Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make a script check when a stat changes then do the following actions when it does?

Asked by 2 years ago

So I made a leaderstats and a value in it. I want to make a script that checks whenever the value is changed and if u possess certain requirements then it will do the following actions. but my script does not do anything when the value changes

local db = true
game.Players.PlayerAdded:Connect(function(plr)
    wait(5)
    local Leader = plr:WaitForChild("leaderstats")
    local ExpStat = Leader:WaitForChild("Exp")
    local Exp = ExpStat.Value
    ExpStat.Changed:Connect(function(Change)
        local ExpGain = Change - Exp
        if ExpGain > 0 then
            if db then db = false
                Exp = Exp - ExpGain
                wait(0.1)
                Exp = Exp + (ExpGain * 2)
                wait(0.1)
                db = true
            end
        end
    end)
end)

Can you tell me whats wrong because i have no idea

0
There is a requirement there i just removed it temporary for testing TheUltimateTNTFriend 109 — 2y

Answer this question