Why isn't my code working

Hello I am making a script for an explosion hitbox and I can’t figure out why it’s not working
The output only prints “baseplate”

function explode()
	for i, v in pairs(script.Parent:GetTouchingParts()) do
		print(v)
		if v.Parent:WaitForChild("Humanoid") then
			v.Parent.Humanoid.Health = 0
		end
	end
end

while true do
	wait(1)
	explode()
end
1 Like

I can’t help you with your code due to the lack of information provided.

Do you need my workspace or explain more?

I need more than just “Code no work”.

Well I am trying to make it so that every second anyone touching it dies

Hello! I have some questions to give you a solution:

Where is the script located?
What isn’t working?
Does it give any errors?
Why don’t you use .Touched?

what happens is that it doesn’t seem to detect a player touching it

Just do a killbrick script then?

local part = script.Parent

part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health = 0
end)

Okay, that makes sense.


local Part = script.Parent -- save to optimize

Part.Touched:Connect(function(Hit)
local Hum = Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid")

if Hum then
Hum.Health = 0
end
end)

Never mind I was making this way more complicated than it is thank you for solutions anyway.

1 Like

I just will use a kill brick script and can touch to toggle it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.