function onTouched(Obj)
local h = Obj.Parent:FindFirstChild("Humanoid")
if h then
h.Health = 0
end
end
script.Parent.Touched:Connect(onTouched)
This does not fix the error I am having; it’s virtually the same code I wrote
Try using this code:
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 add a short jump cooldown of like 1/2 a second and that should fix the error
How would this refer to the player? I am getting an error in output, here it is;
Output Error
21:37:39.311 - Torso is not a valid member of Model
21:37:39.312 - Stack Begin
21:37:39.312 - Script 'Workspace.Cube.KillScript', Line 6
21:37:39.313 - Stack End
Try setting the kill brick to can-collide false.
I’ve tested it, it does kill the player. So, not sure why that is doing that. As I don’t get that error when I use it.
Where is your brick located? In the workspace?
Is your script a local script, modular script…?
Yes, it’s a script and it’s in the workspace, make sure the script’s parent is the block that you want to kill the player with.
This code may not work with r15, since the torso is divided into UpperTorso and LowerTorso.
Yep, I think that’s the answer. Could HumanoidRootPart work?
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 still spam jump to avoid the kill
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)
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent:BreakJoints()
end
end)
Hey, sorry for necroing, but one problem I see is that you’re using the same variable for the thing touching the part (h) and the humanoid (also h). I’m not sure if this would break the code, but you should avoid doing this.