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

Text Debounce doesn't seem to work?

Asked by
yoshi8080 445 Moderation Voter
8 years ago
Edited 8 years ago

I was making a little thing that talks once clicked, however the debounce to prevent the player from spam click and messing up the text isn't working? It works of course without any errors

01StringMessages = {'Hello My Name Is Bob','I am a lovely NPC','What about you?'}
02Messages = 0
03Sound = script.Parent.Sound
04 
05typing = false
06 
07function NextMessage()
08    Messages = Messages + 1
09    if Messages > #StringMessages then
10        Messages = 1
11        end
12    Length = string.len(StringMessages[Messages])
13end
14 
15script.Parent.ClickDetector.MouseClick:connect(function()
View all 26 lines...

1 answer

Log in to vote
2
Answered by
einsteinK 145
8 years ago

You got this structure:

01function MouseClick()
02    if not typing then
03        -- do stuff
04        typing = false
05    end
06    typing = false
07end
08 
09-- First click: typing is set to false and the for-loop runs
10-- Second click: if-statement is skipped, it does the "typing = false"
11-- Third click: typing is false, so if-statement works again

Solution: Putting the "typing = false" inside the if-statement:

01script.Parent.ClickDetector.MouseClick:connect(function()
02    if not typing then
03        typing = true
04        NextMessage()
05        for i=1,Length do
06            script.Parent.NameGUI.Tex.Text = (string.sub(StringMessages[Messages],1,i))
07            Sound:Play()
08            wait(.25)
09        end
10        typing = false
11    end
12end)
0
Thanks, it was this simple mistake I didn't catch ;) yoshi8080 445 — 8y
Ad

Answer this question