Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with buy script?

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.