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

What is the command to kill a player?

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)

1 comment

0

A reset button?

2 answers

✓ Accepted answer

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)

2 comments

0

Thank you so much

0

No problem.

local plr = --Player

function onKeyPress(inputObject, gameProcessedEvent)
	    if inputObject.KeyCode == Enum.KeyCode.W then
	    workspace[plr.Name].Humanoid.Health = 0
	    end
	end 

1 comment

0

it says "unknown global for plr" do you know what thats about?

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