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

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

Asked by
xam345 5
8 years ago

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 — 4y

Locked by youtubemasterWOW

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

Why was this question closed?

9 answers

Log in to vote
3
Answered by 8 years ago

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

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

Now you want to create a function that kills a players

1function 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.

1Player = part.Parent -- This will refer to the whole player model
2Torso = Player.Torso -- This will refer to the player's Torso
3 
4Torso:Destroy() --This will kill the player
5 
6end --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

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

Overall the script is supposed to look like this

01Lava = script.Parent -- script.Parent will refer to the Part
02 
03function 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
04 
05local Player = part.Parent -- This will refer to the whole player model
06local Torso = Player.Torso -- This will refer to the player's Torso
07 
08Torso:Destroy() --This will kill the player
09 
10end --This is used to signify the end of the function
11 
12Lava.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 — 5y
Ad
Log in to vote
0
Answered by
RoyMer 301 Moderation Voter
8 years ago

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

1script.Parent.Touched:connect(function(hit)
2    if hit.Parent:FindFirstChild("Humanoid") then --This is to check if the hit object is a player
3        hit.Parent:BreakJoints() --This kills him
4    end
5end)
Log in to vote
0
Answered by
Valatos 166
8 years ago

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

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

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

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago
1script.Parent.Touched:connect(function(hit) -- If a player touches the part it connects to the function
2    if hit and hit.Parent and hit.Parent:FindFirstChild('Humanoid') then
3    hit.Parent.Humanoid.Health = 0
4end)
5 
6-- Very Simple
Log in to vote
0
Answered by 5 years ago
1local trapPart = script.Parent
2local function onPartTouch(otherPart)
3    local partParent = otherPart.Parent
4    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
5    if ( humanoid ) then
6        humanoid.Health = 0
7    end
8end
9trapPart.Touched:Connect(onPartTouch)
Log in to vote
0
Answered by 5 years ago

Just try this:

1function onTouch(part)
2    local humanoid = part.Parent:FindFirstChild("Humanoid")
3    if (humanoid ~= nil) then   -- if a humanoid exists, then
4    humanoid.Health = 0 -- damage the humanoid
5end
6end
7 
8script.Parent.Touched:Connect(onTouch)

Put this in your part.

Log in to vote
0
Answered by 4 years ago

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.

Log in to vote
0
Answered by 4 years ago

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

01--Ultronlize
02local Brick = script.Parent
03 
04 
05 
06local function PlayerTouched(Part)
07    local Parent = Part.Parent
08    if game.Players:GetPlayerFromCharacter(Parent) then
09        Parent.Humanoid.Health = 0 --kills the player
10    end
11end
12 
13Brick.Touched:connect(PlayerTouched)
Log in to vote
0
Answered by 4 years ago
1local killbrick = script.Parent
2killbrick.Touched:Connect(function(hit)
3    if hit.Parent.Head then-- Checking if it is a player
4        hit.Parent.Head:Destroy -- This can kill players that are in god mode or force field
5        --
6    end
7end)