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
01 | StringMessages = { 'Hello My Name Is Bob' , 'I am a lovely NPC' , 'What about you?' } |
02 | Messages = 0 |
03 | Sound = script.Parent.Sound |
04 |
05 | typing = false |
06 |
07 | function NextMessage() |
08 | Messages = Messages + 1 |
09 | if Messages > #StringMessages then |
10 | Messages = 1 |
11 | end |
12 | Length = string.len(StringMessages [ Messages ] ) |
13 | end |
14 |
15 | script.Parent.ClickDetector.MouseClick:connect( function () |
You got this structure:
01 | function MouseClick() |
02 | if not typing then |
03 | -- do stuff |
04 | typing = false |
05 | end |
06 | typing = false |
07 | end |
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:
01 | script.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 |
12 | end ) |