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

How do I make this script uninterruptible with keybind activation?

Hi, Im trying to make a Gui wich activates on pressing M. the script works perfectly I just don't know how to make it so it cant be interupted? Because if I press M a couple of time it breaks. With this i mean that M does nothing when the Gui is animating on the screen. Thanks in advance.

local Travel = script.Parent.Parent.Travel

p = game.Players.LocalPlayer
mouse = p:GetMouse()

mouse.KeyDown:connect(function(key)
	if key == "m" then
		if Travel.Visible == true then
			Travel:TweenPosition(
				UDim2.new(0, 0, 0.79, 0), --End Position
				"Out", -- Easing Direction
				"Back", --Easing Style
				2, --How Long Does It Take?
				false --Other Tween Override
				)
				wait(2)
				Travel.Visible = false
		elseif Travel.Visible == false then
			Travel.Visible = true
			Travel:TweenPosition(
				UDim2.new(0.25, 0, 0.79, 0),
				"Out",
				"Back",
				2,
				false
				)
		end
	end
end)

1 comment

0

I was unclear about the ''with this i mean'' part, that sentence is talking about the ''how to make it uninterruptible'' part.

1 answer

✓ Accepted answer

I think a boolean would be applicable to this situation. The player will be unable to spam while the tween is playing.

local Travel = script.Parent.Parent.Travel
p = game.Players.LocalPlayer
mouse = p:GetMouse()
local canPress = true

mouse.KeyDown:connect(function(key)
	if not canPress then -- detect if player can press m
		return -- return nothing if they can't
	end
	canPress = false -- set canPress to false
	if key == "m" then
		if Travel.Visible == true then
			Travel:TweenPosition(
				UDim2.new(0, 0, 0.79, 0), --End Position
				"Out", -- Easing Direction
				"Back", --Easing Style
				2, --How Long Does It Take?
				false --Other Tween Override
			)
			wait(2)
			Travel.Visible = false
		elseif Travel.Visible == false then
			Travel.Visible = true
			Travel:TweenPosition(
				UDim2.new(0.25, 0, 0.79, 0),
				"Out",
				"Back",
				2,
				false
			)
			wait(2) --add wait
		end
	canPress = true -- set canPress to true again
	end
end)

1 comment

0

It worked! Amazing work thank you!

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