Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

3 comments

0

Yup that helped. Thank you for your fast response, probably avoided me hours of scratching my head )))

0

Glad it helped. Please accept answers :)

0

Did it mate)

This discussion is preserved as it was. New answers, comments, and votes are closed.