How do I make a script detect if a button was pressed a second time?

here’s the script:

local UserInputService = game:GetService('UserInputService')

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.One then
			slot:TweenPosition(
				UDim2.new(0.316, 0,0.89, 0), --makes it go to another/new position if that makes sense
				"Out",
				"Quad",
				.1,
				true
			)
		else
			slot:TweenPosition(
				UDim2.new(0.316, 0,0.898, 0), --makes it go back to it's normal position
				"Out",
				"Quad",
				.1,
				true
			)
		end
	end
end)```
2 Likes

fix your script first pls you accidentaly place the ``` down when your supposed to put it all the way up

2 Likes

There are other posts asking this but this should help you do that.

local slot = script.Parent
local UserInputService = game:GetService("UserInputService")
local keypress = {Enum.KeyCode.One,0}

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if not(gameProcessedEvent) then return end
if input.UserInputType == Enum.UserInputType.Keyboard then
	if input.KeyCode == keypress[1] then
		if (keypress[2] == 0) then
			keypress[2] = 1
			slot:TweenPosition(
				UDim2.new(0.316, 0,0.89, 0), --makes it go to another/new position if that makes sense
				"Out",
				"Quad",
				.1,
				true
			)
		else
			slot:TweenPosition(
				UDim2.new(0.316, 0,0.898, 0), --makes it go back to it's normal position
				"Out",
				"Quad",
				.1,
				true
			)
		end
	end
end
end)

while wait() do
	if keypress[2] == 1 then
		wait(1) -- you can change
		keypress[2] = 0
	end	
end
1 Like

script isn’t working, i checked the output there is nothing in there.

ok then remove if not(gameProcessedEvent) then return end

1 Like

yoo! thanks for helping to figure this out.

1 Like