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

Why isn't this KeyDown script working?

My script resets a player when a tool is selected and "r" is pressed. The script is a LocalScript and is in a Tool.

function onKeyDown(key) 
	key:lower() 
	if key == "r" then 
		game.Players.LocalPlayer.Character.Humanoid.Health = 0
	end
end 
 
 
function onSelected(mouse) 
	mouse.KeyDown:connect(onKeyDown) 
end 

script.Parent.Selected:connect(onSelected)

But it doesn't do anything. Can anyone help me out?

2 comments

0

Try and use the 'Equipped' event.

0

Equipped works. Thanks!

1 answer

I've tested this in studio, and it seems to work just fine. Perhaps you made it a Script instead of a LocalScript?

4 comments

0

No, I'm certain it's a LocalScript.

0

Hm, if it's in the correct place(Being the child of the Hopperbin) then I am not sure. Are there any error messages in the output?

0

No

0

Could you screenshot the Explorer and the Script editor for me?

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