I am trying to create an obstacle course, so I need a brick that instantly kills the player when it’s touched. In the example below the red brick is supposed to kill instantly, but if you hold jump you can avoid the kill. Does anybody know any better ways to do this?
The Script
function onTouched(h)
local h = h.Parent:FindFirstChild("Humanoid")
if h ~= nil then
h.Health = 0
end
end
script.Parent.Touched:Connect(onTouched)
local 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 character = part.Parent -- This will refer to the whole character
local torso = character.Torso -- This will refer to the character'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 would just go with head. However, I’m not sure if this will fix the problem from the OP. The OP is trying to find a more reliable way to use .Touched events, since they sometimes don’t fire.
I assume your kill brick works if you don’t hold the jump button?
Instead of making the red part be the kill brick, you should instead make a non-collidable invisible part offset by one or 1.5 studs up. That way, you don’t only target the jumping people, but also the people wearing the levitation pack
You can make an invisible not collisionable part on top of the red part, as it has no collisions, the character will sink into the part. Edit: @PlantChampion we wrote the same at the same time.
and @Nightrains (I won’t forget you) this works as a temporary solution . I hope in the future there could be a better solution, but thanks for bringing this idea to my attention!
To fix this in my game I made all the events and tweens on the clients. Since it’s on the client there is no latency and things happen immediately as well as lagless tweens. The events are on the client though, which means it can be easily exploited but it works pretty well.
Hm… that’s actually pretty smart, I may try this. Exploitations are not too big of an issue I am looking out for so it’s possibly something I could look into.
Love the videos, by the way. I learned a lot from your trading guides (even though I got scammed)