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

Script isn't detecting the key being pressed?

I am working on a script that activates certain moves if a key is pressed. Everything seems to be good except for the fact that it's not picking up the key being pressed.

local UserInputService = game:GetService("UserInputService")

local Key = script.Parent
local Hotbar = game.Players.LocalPlayer.PlayerGui.PlayerGUI.Hotbar
local Slot = script.Parent.Parent
local Quirk = game.Workspace.Quirk

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Key then
		if Hotbar.Visible == true then
			if Quirk ~= "NA" then
				Slot.BackgroundTransparency = 0.5
				-- add the script that activates the quirk move by setting the remote event name to the specific quirk move name?
			end
		end
	end
end)

At first I had line 9 as:

if input.KeyCode == Enum.KeyCode.Key then

And this gave me an output error saying that Key was not a member/child of KeyCode when I pressed the key, so I tried fixing it by making it what it is in the first script, but now I get nothing from the output when the key is pressed. What do I do?

2 comments

0

Why do you have the keycode set to the script's parent?

0

Because the script's parent is a string value with the keycode. I know it seems dumb but I did it because the main parent of all this will need to be cloned with a script and I wouldn't be able to access the clones' keycodes if they're in a script

1 answer

✓ Accepted answer

replace

local Key = script.Parent

with

local Key = Enum.KeyCode.A --key you want to detect

also if you're trying to detect if workspace.Quirk is nil or not there you can do

if Quirk then
--your code here
end

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