#Wont subtract Points

4 messages · Page 1 of 1 (latest)

old blade
#
local Cost = script.Parent.Parent.Cost

local db = true
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then 
        if db == true then
            db = false
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            
            if player.leaderstats.Points.Value >= Cost.Value then
            player.leaderstats.Points.Value -= Cost.Value
            script.Parent.CanCollide = false
                
            wait(5)
            db = true
            script.Parent.CanCollide = true
            end
        end
    end
end)

When i Hit the wall or the "door" it doesnt subtract the Coins and let me go through idk whats wrong my script seems perfectly fine and no errors in output

fading cradle
# old blade ```lua local Cost = script.Parent.Parent.Cost local db = true script.Parent.Tou...

You're right, it runs perfectly with a small exception, the debounce will only be set back to true IF the player was able to afford the cost, so it'll stay false forever if one dude was broke.
Moved the debounce reset out of the if-statement, should hopefully work now

local Cost = script.Parent.Parent.Cost

local db = true
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then 
        if db == true then
            db = false
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            
            if player.leaderstats.Points.Value >= Cost.Value then
                player.leaderstats.Points.Value -= Cost.Value
                script.Parent.CanCollide = false
                
                wait(5)
                script.Parent.CanCollide = true
            end
            db = true
        end
    end
end)
old blade
fading cradle
#

No problem, glad I could help!