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

How can I make it so when a player touches a brick, they die?

Asked by 11 years ago

I need help doing this. I am gonna make an obby.

6 answers

Log in to vote
3
Answered by
ultrabug 306 Moderation Voter
11 years ago

You can use the Touched event with a part like so:

1part.Touched:connect(function(hit)

And then you can find out if the part belongs to a player like this:

1humanoid=hit.Parent:FindFirstChild("Humanoid")
2if humanoid ~=nil then

And then you can use your favorite method for killing a player, here is mine:

1hit.Parent.Torso:Destroy()

And then all together we have this:

1part.Tocuehd:connect(function(hit)--Touched event!
2    humanoid=hit.Parent:FindFirstChild("Humanoid")--Finding the Humanoid!
3    if humanoid ~=nil then--If the humanoid exists!
4        hit.Parent.Torso:Destroy()--Killing the player!
5    end
6end)
Ad
Log in to vote
0
Answered by 11 years ago

Use a script that upon touch humanoid health = 0

In obbies, people like chances, so make it upon touch damage humanoid 30 to 40

Log in to vote
0
Answered by 11 years ago

You can use this script:

1function Touched(hit)
2humanoid-hit.Parent.findFirstChild("Humanoid")
3if Humanoid ~=nil then
4Instance.new("Part, Head")
5hit.Head:Destroy()
6end
7end
8 
9script.Parent.onTouched:connect(hit)
0
I am a dev myself (please check out my games btw) and the script I use is this one 6_09x 0 — 4y
Log in to vote
0
Answered by
stix619 15
11 years ago

Hello Allisaurus!

This simple script will kill a player on touch.

The green text explains what each part does.

01bin = script.Parent --This is a variable. We can use this later, in the function.
02 
03function onTouched(Part2) --This is the function.
04    local h = Part2.Parent:FindFirstChild("Humanoid") --We are searching for the player's body here.
05    if h then --If it is there, then....
06        while h.Health > 0 do --Check if it's health is greater than zero. I'm not sure if this is needed, but I keep it anyway.
07        h.Health = h.Health - 100 --Take away the player's health.
08        wait(1) --Waits a second. Probably not needed either, but whatever.
09        end
10    end
11end --Ends the function.
12 
13bin.Touched:connect(onTouched) --This connects the function.

I hope this helps. Good luck with your obby!

Log in to vote
0
Answered by
6_09x 0
4 years ago

script i use is 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
and put it on the part so like add a script to the part 6_09x 0 — 4y
Log in to vote
-1
Answered by 11 years ago

It's easy, you would just need a upontouched(), and a function to take the players health down to zero. On free models, there are loads of scripts that do exactly that.

0
Free models? Pfffffffft 6_09x 0 — 4y

Answer this question