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

How do I use Key Events or are they outdated?

Asked by 8 years ago

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

Log in to vote
2
Answered by 8 years ago

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
* UserInputService
* InputBegan

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.

Ad
Log in to vote
0
Answered by 8 years ago

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)
0
Your capitalisation of Lua keywords will kill the script User#6546 35 — 8y
0
Sorry, I was rushing while doing this. You should be able to figure out how to do locals without my help, anyway. TheDeadlyPanther 2460 — 8y

Answer this question