Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't this script work?

Asked by 10 years ago
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

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

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)

Ad

Answer this question