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

Keybinding not working at all, unable to fix it. What am I doing wrong?

Alright so, i'm a relatively new scripter on ROBLOX and i've been trying to figure out what I am missing. Nothing has worked to get this to work and i'm entirely lost on what i'm missing. Basically, i'm trying to get the script to when I hit T it searches to see if the tween is already in position one and if it is, then to move it to position two and vice versa. I was able to get the mouse part to work but I don't know how to do the rest. I want this to be able to be on a loop, meaning it works after one press.

local frame = script.Parent.Parent.Parent:WaitForChild("Titantrons")
local frame2 = game.Players.LocalPlayer.PlayerGui.ControlGUI.Frame:WaitForChild("Titantrons")
local hotkey = Enum.KeyCode.T
local UIS = game:GetService("UserInputService")
local toggle = false
--First Script [For the Keybind]
UIS.InputBegan:Connect(function(key, gp)
	if key == hotkey then
		if UIS:GetFocusedTextBox() == nil then
		if toggle == false then
frame2:TweenPosition(UDim2.new(0.003,0,0,0), 'Out', 'Bounce', 1)
		toggle = true
	else 
frame2:TweenPosition(UDim2.new(0.003,0,1.3,0), 'Out', 'Bounce', 1)
		toggle = false
			end
		end
	end
end)
-- Second script [For the Mouse Click] Works Fine
script.Parent.MouseButton1Click:Connect(function(click)
		if toggle == false then
frame:TweenPosition(UDim2.new(0.003,0,0,0), 'Out', 'Bounce', 1)
		toggle = true
	else 
frame:TweenPosition(UDim2.new(0.003,0,1.3,0), 'Out', 'Bounce', 1)
		toggle = false
		
	end
end)

Thanks in advance to anyone who helps.

1 comment

1

On line 8, to see if key.KeyCode is equal to hotkey, not if key is equal to hotkey.

1 answer

✓ Accepted answer

Add KeyCode at the end of your if key You are confusing the deprecated method Key Down with UIS.

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