(Those blocks that kill you when you touch them)
fairly simple:
script.Parent.Touched:connect(function(hit) -- gets the killbrick, and runs this code when it is touched if hit and hit.Parent:FindFirstChild("Humanoid") then -- finds out if it hit a humanoid (aka character NPC or other model with a humanoid) hit.Parent.Humanoid.Health = 0 -- kill end end)
this script should be in a part
EDIT: A bit more information. The way killbricks usually work is to first use a Touched connect function to detect when the killbrick hits or is hit by another part (on line 1) afterwords, it finds out whether the thing that hit it was part of a player (not the player object) and then changes the player's humanoid health to 0, killing it. Note: you can change values other than Health:
hit.Parent.Humanoid.WalkSpeed = 50 -- superspeed!
or
hit.Parent.Humanoid.JumpPower = 200 -- super jump!
Well, it's really simple really. First you must have a brick, and add a script inside of this brick.
In the script you'll need to add this line.
script.Parent.Touched:connect(function(hit) end)
this says 'when this brick is touched something will happen'. Now we need to add a few lines checking to see if what is touching it is 'alive'.
script.Parent.Touched:connect(function(hit) if hit.Parent then -- new line that I added local hum = hit.Parent:FindFirstChild("Humanoid") -- new line that I added if hum then -- new line that I added else -- new line that I added print("Not human") -- new line that I added end -- new line that I added end -- new line that I added end)
What I just did checked to see if one, the part was touched, and if whatever touched said part has a Humanoid inside of it, otherwise it will print to the output/console that it isn't 'Human'. Now what we need to do is well kill it if it is human.
script.Parent.Touched:connect(function(hit) if hit.Parent then local hum = hit.Parent:FindFirstChild("Humanoid") if hum then -- new line that I added print("Is Human") -- new line that I added hum.Health = 0 -- new line that I added else print("Not human") end end end)
Now if it is human, it will put in the output or console saying that it is human, and then kill it as well.
Now remember next time, not to ask us to make a script for you, that is not the purpose of this website, our purpose is to HELP you with your script that YOU have already attempted to make. As the name is ScriptingHelpers and not ScriptCreators
Closed as Not Constructive by Leamir, Vulkarin, IcyEvil, and green271
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?