Still have questions? Join our Discord server and get real time help.
1

# how do you make a block "kill" a player? [closed]

I am trying to create a obby on roblox and I am having trouble with the code for if a player touches the block to kill that player. It would be some really boring lava jumps without this! thanks for the help!

0
Why are people still looking at this.. Nistrict 44 — 7mo

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

3

Simple, so start by creating a part and a script and placing it under the part

First start by making a variable for the part

Lava = script.Parent -- script.Parent will refer to the Part


Now you want to create a function that kills a players

function Kill(part) -- You use the keyword "function" to declare a function and the word after it is the name of the function and the word between the brackets is called the parameter, in this example it will refer to the object that touched the Lava


Now to the killing part, but first we need to get the humanoid of the object or the torso/head to kill the player, I prefer getting the torso to do it.

Player = part.Parent -- This will refer to the whole player model
Torso = Player.Torso -- This will refer to the player's Torso

Torso:Destroy() --This will kill the player

end --This is used to signify the end of the function


Now we are done with what the lave is supposed to do, now to make it happen when the player touches the lava

lava.Touched:connect(Kill) -- We use the .Touched event to call our function


Overall the script is supposed to look like this

Lava = script.Parent -- script.Parent will refer to the Part

function Kill(part) -- You use the keyword "function" to declare a function and the word after it is the name of the function and the word between the brackets is called the parameter, in this example it will refer to the object that touched the Lava

local Player = part.Parent -- This will refer to the whole player model
local Torso = Player.Torso -- This will refer to the player's Torso

Torso:Destroy() --This will kill the player

end --This is used to signify the end of the function

Lava.Touched:connect(Kill) -- We use the .Touched event to call our function


I recommend you check out Roblox's tutorials so yoo can get better at scripting

0
nah.... Just use free models.... jk AllanBill06 -11 — 1y
0
RoyMer 296
4 years ago

This is to kill a player, put it inside the block.

script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then --This is to check if the hit object is a player
hit.Parent:BreakJoints() --This kills him
end
end)

0
Valatos 166
4 years ago

I mainly use this one, i'm sure this works cause i use this much

script.Parent.Touched:connect(function(hit) -- If a player touches the brick it connects to the function
local h = hit.Parent:FindFirstChild("Humanoid") -- Finds the humanoid
if h then -- Just a check if there is a humanoid (Will gives errors if you delete this)
if h.Health > 0 then -- Checks if the humanoid health is above 0
h.Health = 0 -- Sets the health to 0
end
end
end)


Hope this works for you :D, if it works accept this answere :P

0
Edited 4 years ago
script.Parent.Touched:connect(function(hit) -- If a player touches the part it connects to the function
if hit and hit.Parent and hit.Parent:FindFirstChild('Humanoid') then
hit.Parent.Humanoid.Health = 0
end)

-- Very Simple

0
local trapPart = script.Parent
local function onPartTouch(otherPart)
local partParent = otherPart.Parent
local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
if ( humanoid ) then
humanoid.Health = 0
end
end
trapPart.Touched:Connect(onPartTouch)

0

Just try this:

function onTouch(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if (humanoid ~= nil) then   -- if a humanoid exists, then
humanoid.Health = 0 -- damage the humanoid
end
end

script.Parent.Touched:Connect(onTouch)


0

This can be simple, all you have to do is get a block you want to kill a player, put a script into it and paste this into the script :

local debounce = false local HealthLoss = 100 function OnTouched(Part) if Part.Parent ~= nil then if debounce == false and Part.Parent:findFirstChild("Humanoid") ~= nil then debounce = true Part.Parent:findFirstChild("Humanoid"):TakeDamage(HealthLoss) wait(2) debounce = false end end end script.Parent.Touched:connect(OnTouched)

This script will work, though if you want you can change the 100 to whatever you want to make sure the player is dead.

0

Here is the script I use for a kill block... place the script inside the part where you want the players to die from.

--Ultronlize
local Brick = script.Parent

local function PlayerTouched(Part)
local Parent = Part.Parent
if game.Players:GetPlayerFromCharacter(Parent) then
Parent.Humanoid.Health = 0 --kills the player
end
end

Brick.Touched:connect(PlayerTouched)

local killbrick = script.Parent