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 6 years ago
Edited 6 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

button = script.Parent.button
frame = script.Parent.Parent.ColorsAvailable.Frame
stop = script.Parent.button.waiting
stop1 = script.Parent.button.waiting.dot1
stop2 = script.Parent.button.waiting.dot2
stop3 = script.Parent.button.waiting.dot3
text = script.Parent.button.TextButton
mouse= game.Players.LocalPlayer:GetMouse()
a=0
mouse.KeyDown:connect(function(key)
if (string.lower(key) == "c") and (a==0) then
    a=1
game.Soundscape.buttonpress.PlaybackSpeed = 1
game.Soundscape.buttonpress:Play(1)

  frame:TweenPosition(UDim2.new(0.2,-100,0.9,0), 'Out', 'Quad', 0.35)
  button:TweenPosition(UDim2.new(0.2,-100,0.8,20), 'Out', 'Quad', 0.175)
text.Visible = false 
stop.Visible = true
wait(0.0875)
 stop1.Visible = true
wait(0.0875)
 stop2.Visible = true
wait(0.0875)
 stop3.Visible = true
wait(0.0875)
text.Visible = true
 stop.Visible = false
 stop1.Visible = false
 stop2.Visible = false
 stop3.Visible = false

elseif(string.lower(key)=='c') and (a==1) then 
    a=0
    game.Soundscape.buttonpress.PlaybackSpeed = 1.5
    game.Soundscape.buttonpress:Play(1) 
frame:TweenPosition(UDim2.new(0.2,-100,1,0), 'In', 'Quad', 0.35)
button:TweenPosition(UDim2.new(0.2,-100,0.9,0), 'In', 'Quad', 0.35)
text.Visible = false  
stop.Visible = true
wait(0.0875)
 stop1.Visible = true
wait(0.0875)
 stop2.Visible = true
wait(0.0875)
 stop3.Visible = true
wait(0.0875)
text.Visible = true
 stop.Visible = false
 stop1.Visible = false
 stop2.Visible = false
 stop3.Visible = false
end    
end)

1 answer

Log in to vote
1
Answered by 6 years ago

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

tweening = false --Another debounce for tween control
a=0
mouse.KeyDown:connect(function(key)
    if (string.lower(key) == "c") and (a==0) and tweening == false then --If not tweening already
        tweening = true --Change tweening to true so that another tween can't happen while already tweening
        a = 1
        tweening = false
    elseif(string.lower(key)=='c') and (a==1) and tweening == false then --If not tweening already
        tweening = true
        a = 0
        tweening = false
    end
end)

Hope that helps

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

Answer this question