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

Add debounce help?

I don't know how to add a debounce :(



game.Workspace.GuiTextChanged.Touched:connect(function(PartTouched)
	
local Text1 = "2#dwadwadwadwadawd d asd as das8"
local Player = game.Players:GetPlayerFromCharacter(PartTouched.Parent)

	Player.PlayerGui.TalkingGui.Frame.TextLabel.Visible = true
	

	local function Type(Text)
 local CurrentText = Player.PlayerGui.TalkingGui.Frame.TextLabel.Text
 local Length = Player.PlayerGui.TalkingGui.Frame.TextLabel.Text:len()
 for i = Length,0,-1 do
  wait()
  Player.PlayerGui.TalkingGui.Frame.TextLabel.Text = CurrentText:sub(0,i)
 end
 wait(.5)
 local Length = Text:len()
 for i = 1,Length do
  wait()
  Player.PlayerGui.TalkingGui.Frame.TextLabel.Text = Text:sub(1,i)
 end
end

wait(2)
Type(Text1)
wait(2)
Type("")

Player.PlayerGui.TalkingGui.Frame.Visible = false
	
	
	
end)

1 answer

✓ Accepted answer

First you would define the debounce as what ever you want such as:

local stop = false

Then you would check if it is false at the first line of you function like:

if not stop then
end

Then you want to make it active like:

if not stop then
stop = true
end

then after the click or touch the thing you want to disable it for how many seconds like:

if not stop then
stop = true
wait(5) -- how ever long you want it to be
stop = false
end

the full script would be:

local stop = false
game.Workspace.GuiTextChanged.Touched:connect(function(PartTouched)
if not stop then
stop = true
local Text1 = "2#dwadwadwadwadawd d asd as das8"
local Player = game.Players:GetPlayerFromCharacter(PartTouched.Parent)

    Player.PlayerGui.TalkingGui.Frame.TextLabel.Visible = true


    local function Type(Text)
 local CurrentText = Player.PlayerGui.TalkingGui.Frame.TextLabel.Text
 local Length = Player.PlayerGui.TalkingGui.Frame.TextLabel.Text:len()
 for i = Length,0,-1 do
  wait()
  Player.PlayerGui.TalkingGui.Frame.TextLabel.Text = CurrentText:sub(0,i)
 end
 wait(.5)
 local Length = Text:len()
 for i = 1,Length do
  wait()
  Player.PlayerGui.TalkingGui.Frame.TextLabel.Text = Text:sub(1,i)
 end
end

wait(2)
Type(Text1)
wait(2)
Type("")

Player.PlayerGui.TalkingGui.Frame.Visible = false
wait(5) -- how long you want it to be
stop = false

end
end)

Hope it helped for more debounce go to: http://wiki.roblox.com/index.php?title=Debounce

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