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

What is the command to kill a player? [closed]

Asked by 5 years ago

I have a basic script here that when "W" is pressed something will happen, but what I need to happen I don't know the code for.. Does anyone know what the code is that will kill the player if touched?

function onKeyPress(inputObject, gameProcessedEvent)

    if inputObject.KeyCode == Enum.KeyCode.W then
    --What goes here?-- 
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)
0
A reset button? NiniBlackJackQc 1562 — 5y

Closed as Not Constructive by User#19524

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
0
Answered by 5 years ago

If this is a LocalScript which I think it is I think this will work.

local player = game.Players.LocalPlayer

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.W then
        player.Character:BreakJoints() -- or player.Character.Humanoid:TakeDamage(999)
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)
0
Thank you so much 1020x802 -3 — 5y
0
No problem. DjinoKip 78 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

local plr = --Player

function onKeyPress(inputObject, gameProcessedEvent)
        if inputObject.KeyCode == Enum.KeyCode.W then
        workspace[plr.Name].Humanoid.Health = 0
        end
    end 
0
it says "unknown global for plr" do you know what thats about? 1020x802 -3 — 5y