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

How do I use Key Events or are they outdated?

So I have been trying to make it so when I press E in my game it will make your player die but this script won't work ???? if key == "e" then game.Workspace.NameHere.Humanoid.Health = 0 end

Help ????

2 answers

KeyDown is deprecated, consider moving to UIS

local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService");

UIS.InputBegan:connect(function(input,proc)
if proc and input.KeyCode == Enum.KeyCode.E then
(player.Character or player.CharacterAdded:wait()):BreakJoints(wait())
end
end)

Take a look at these

If you're curious about where I've written

(player.Character or player.CharacterAdded:wait()):BreakJoints(wait())

it simply makes sure that the Character exists, and then wait()s for it to load before killing it evilly.

This script needs to be a LocalScript in StarterPack:

Local player = game.Players.LocalPlayer
Local mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
key = key:lower()
If key == "e" then
player.Character:BreakJoints() -- kills player
End
End)

2 comments

0

Your capitalisation of Lua keywords will kill the script

0

Sorry, I was rushing while doing this. You should be able to figure out how to do locals without my help, anyway.

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