How come this script won't work?

Hey Developers this script is for a obby and I am wondering why this doesn’t work? There are no errors.

local KillParts = script.Parent:GetChildren()

for i, part in pairs(KillParts) do
	if part:IsA("Part") then
		part.Touched:Connect(function(otherpart)
			if otherpart.Parent:FindFirstChild("Humanoid") then
				otherpart.Parent.Health = 0
			end
		end)
	end
end

change otherpart.Parent.Health to otherpart.Parent.Humanoid.Health since models doesn’t have “Health” property and I’m pretty sure it was just a typing mistake.

2 Likes

i tried it and it still didnt work :expressionless: any other suggestions?

Is the killpart’s classname “Part”? I’d prefer using “BasePart”.

1 Like

the kill parts is actually a cylinder so if I changed it to BasePArt that should work?

It should work since Cylinder isnt a Part.

1 Like

still doesn’t work this is what the script is looking like rn, ``` local KillParts = script.Parent:GetChildren()

for i, part in pairs(KillParts) do
	if part:IsA("BasePart") then
		part.Touched:Connect(function(otherpart)
			if otherpart.Parent:FindFirstChild("Humanoid") then
				otherpart.Parent.Humanoid.Health = 0
			end
		end)
	end
end

and heres what you need to see in explorer
image

I just realised what has gone wrong with my code sorry for taking ur time but script is in server script service not the child of kill parts tho baseparts thing has saved me thank u!

oh alright then. good luck with your game!

1 Like

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