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

Help with buy script?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

With this script, you can buy a bunch of gravitycoils (I DO NOT WANT THIS). I want it where you have to wait 10 secs before getting another one.

script.Parent.Touched:connect(function(hit)
    local hum = hit.Parent:WaitForChild("Humanoid")
    local tool = game.ServerStorage:WaitForChild("GravityCoil")
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    local stats = plr:WaitForChild("leaderstats").Tags
    local d = false
    if d == false then
        if stats.Value >= 50 then
            d = true
            if hum then
                tool:Clone().Parent = plr.Backpack
                --stats.Value = stats.Value - 10
            end
            wait(10)
            d = false
        end
    end
end)

1 answer

Log in to vote
2
Answered by 8 years ago

You need to store you debounce outside of the event or you will create it each time the event is ran

local d = true -- you want to store the value not create a new var every time

script.Parent.Touched:connect(function(hit)
    local hum = hit.Parent:WaitForChild("Humanoid")
    local tool = game.ServerStorage:WaitForChild("GravityCoil")
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    local stats = plr:WaitForChild("leaderstats").Tags

    if d then -- logic only runs if true so you dont need to use false
        if stats.Value >= 50 then
            d = false
            if hum then
                tool:Clone().Parent = plr.Backpack
                --stats.Value = stats.Value - 10
            end
            wait(10)
            d = true
        end
    end

end)

Hope this helps

Ad

Answer this question