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

Add debounce help?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

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

Log in to vote
1
Answered by 8 years ago

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

Ad

Answer this question