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

How would i go about making a debounce for this code?

script.Parent.MouseButton1Click:Connect(function()

	local tweenService = game:GetService("TweenService")
	local Properties = {
		Position = Vector3.new(-15.5, 1, 42.5)	
	}
	local tweenInfo = TweenInfo.new(2,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut)
	local tween = tweenService:Create(game.Workspace.MoneyGiver,tweenInfo,Properties)

	tween:Play()
	
	wait(3.5)
	
	local tweenService = game:GetService("TweenService")
	local Properties = {
		Position = Vector3.new(-15.5, -17, 42.5)	
	}
	local tweenInfo = TweenInfo.new(2,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut)
	local tween = tweenService:Create(game.Workspace.MoneyGiver,tweenInfo,Properties)
	
	tween:Play()
end)

I want it so that you click a surfacegui, no clickdetector, and theres a cooldown before the next script.

1 answer

✓ Accepted answer

Just add a simple wait()

local debounce = true
script.Parent.MouseButton1Click:Connect(function()

if debounce = true then
	debounce = false
    local tweenService = game:GetService("TweenService")
    local Properties = {
        Position = Vector3.new(-15.5, 1, 42.5)  
    }
    local tweenInfo = TweenInfo.new(2,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut)
    local tween = tweenService:Create(game.Workspace.MoneyGiver,tweenInfo,Properties)

    tween:Play()

wait(3.5)
debounce = true
end

end)

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