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

Why doesn't this script work?

plr = game.Players.LocalPlayer
mouse = plr:getMouse()

function q(key)
	if key == q then
		plr.Character.Humanoid.Health = 0
	end
end
mouse.KeyDown:connect(q)

When you press q you're supposed to die. But it doesn't work, any help?

1 answer

✓ Accepted answer

The KeyDown event returns a string, containing the key you pressed. I'll repeat that, a string. You have to compare the key with a string for this to work, and I suggest using string.lower while comparing the key.

plr = game.Players.LocalPlayer
mouse = plr:GetMouse()
 
function q(key)
    if key:lower() == "q" then
        plr.Character.Humanoid.Health = 0
    end
end
mouse.KeyDown:connect(q)

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