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 ????
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.
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)