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

How to lock a key so it cant be pressed anymore for a period of time?

Asked by 7 years ago
Edited 7 years ago

So i made a script to open a gui when you press a key but if you will mash the key the gui will kinda brake. I want to know if there is a way to block they key when the gui is tweening so it doesnt bug it out

01button = script.Parent.button
02frame = script.Parent.Parent.ColorsAvailable.Frame
03stop = script.Parent.button.waiting
04stop1 = script.Parent.button.waiting.dot1
05stop2 = script.Parent.button.waiting.dot2
06stop3 = script.Parent.button.waiting.dot3
07text = script.Parent.button.TextButton
08mouse= game.Players.LocalPlayer:GetMouse()
09a=0
10mouse.KeyDown:connect(function(key)
11if (string.lower(key) == "c") and (a==0) then
12    a=1
13game.Soundscape.buttonpress.PlaybackSpeed = 1
14game.Soundscape.buttonpress:Play(1)
15 
View all 54 lines...

1 answer

Log in to vote
1
Answered by 7 years ago

You could use another debounce. For example, this could be the outline for your code:

01tweening = false --Another debounce for tween control
02a=0
03mouse.KeyDown:connect(function(key)
04    if (string.lower(key) == "c") and (a==0) and tweening == false then --If not tweening already
05        tweening = true --Change tweening to true so that another tween can't happen while already tweening
06        a = 1
07        tweening = false
08    elseif(string.lower(key)=='c') and (a==1) and tweening == false then --If not tweening already
09        tweening = true
10        a = 0
11        tweening = false
12    end
13end)

Hope that helps

0
Yup that helped. Thank you for your fast response, probably avoided me hours of scratching my head ))) misterdimacugut 11 — 7y
0
Glad it helped. Please accept answers :) dpark19285 375 — 7y
0
Did it mate) misterdimacugut 11 — 7y
Ad

Answer this question