Player can get killed by part, but not parts inside a player model

In my game, I have a script where if you touch a part with a value named “kills” in it, it would kill the player. If the value is in a normal part, it would work but if the part is in a part in a player, it doesn’t work.

This is the script that kills the player:

for i, v in pairs(game.Workspace:GetDescendants()) do
	if v:IsA("BasePart") then
		if v:FindFirstChild("kills") then
			v.Touched:Connect(function(touch)
				if touch.Parent:FindFirstChild("Humanoid") then
					touch.Parent.Humanoid.Health = 0
				end
			end)
		end
	end
end
1 Like

Hey, I don’t know why that would happen but,

I have a script where if you touch a part with a value named “kills” in it

Don’t do that. Use CollectionService.

(Never do :GetDescendants() on game.Workspace three exclamation marks!!!)

1 Like

LocalScript in StarterPlayerScripts

game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
	character.Humanoid.Touched:Connect(function(other)
		if other:FindFirstChild("kills") then
			-- do your damaging in here
		end
	end)
end)

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