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 9 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 9 years ago

KeyDown is deprecated, consider moving to UIS

1local player = game.Players.LocalPlayer
2local UIS = game:GetService("UserInputService");
3 
4UIS.InputBegan:connect(function(input,proc)
5if proc and input.KeyCode == Enum.KeyCode.E then
6(player.Character or player.CharacterAdded:wait()):BreakJoints(wait())
7end
8end)

Take a look at these
* UserInputService
* InputBegan

If you're curious about where I've written

1(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 9 years ago

This script needs to be a LocalScript in StarterPack:

1Local player = game.Players.LocalPlayer
2Local mouse = player:GetMouse()
3 
4mouse.KeyDown:connect(function(key)
5key = key:lower()
6If key == "e" then
7player.Character:BreakJoints() -- kills player
8End
9End)
0
Your capitalisation of Lua keywords will kill the script User#6546 35 — 9y
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 — 9y

Answer this question