Is touched event suitable here?

My goal is to kill the player when the tile falls down and hits them.

Currently I am using a touched event to signal when the player touches the ‘kill_Part’ that is welded to the tile.

local function touched_Kill_Part(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Name == "HumanoidRootPart" then
		local char = hit.Parent
		local hum = char.Humanoid
		local plr = game.Players:GetPlayerFromCharacter(char)
		
		if hum.Health > 0 then
			hum.Health = 0
			
			if plr then
				table.remove(players_In_Game, table.find(players_In_Game, plr))
			end
		end
	end
end

local kill_Part = Instance.new("Part")
		-- add weld constraint
		local weld = Instance.new("WeldConstraint")
		weld.Parent = kill_Part
		weld.Part0 = kill_Part
		weld.Part1 = tile
		--
		kill_Part.Transparency = 0.5
		kill_Part.CanCollide = false
		kill_Part.Anchored = false
		kill_Part.BrickColor = BrickColor.Yellow()
		kill_Part.CastShadow = false
		--
		kill_Part.Size = Vector3.new(30, 2, 30)
		kill_Part.CFrame = CFrame.new(tile.Position.X, tile.Position.Y - tile.Size.Y/2 - kill_Part.Size.Y/2, tile.Position.Z)
		kill_Part.Parent = tile
		
		-- connecting kill part to the kill function
		kill_Part.Touched:Connect(touched_Kill_Part)

twe_Service:Create(tile, TweenInfo.new(speed, Enum.EasingStyle.Quint, Enum.EasingDirection.In), {CFrame = CFrame.new(pos.Position.X, pos.Position.Y - pos.Size.Y/2 + extra + tile.Size.Y/2, pos.Position.Z)}):Play()

Just ignore the tile and other stuff and just picture that there is a part with another part welded to the bottom and will fire the ‘touched_Kill_Part’ function when touched. You might like to know that I am moving the tile by tweening it to the desired position where it will land on the tower. Let me know if there’s a better way of doing this.

In my situation I thought touched event would be fine as the tile just falls from the sky so it seems pretty simple. However the touched event is so unreliable and I would like to try and do it another way.

What other ways do you suggest I go about this?

Any feedback/help is appreciated.

(Also here is a screenshot so you can visualise what the tile looks like)

That’s not going to work. The hit will likely return “Head” or “LeftLowerLeg” or something like that. It is unlikely it will return HumanoidRootPart. Get rid of that and it should work.

1 Like

The hit can infact be the HumanoidRootPart, since it can be touched.

To ensure that this only attacks players, you can use:

local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and hit.Name == "HumanoidRootPart" then
    -- code
end

Here, the code will only run if the hit was owned by a player, and the hit was the HumanoidRootPart. It’s important to pick a limb to detect, and not detect the character as a whole. Some characters are bigger than others, and bigger characters have a bigger hitbox. The root part stays the same size!

take out and hit.Name == "HumanoidRootPart" ?

because you’re narrowing it down to a specific part, there are chances that the part may not even hit the HumanoidRootPart but hits another limb instead.

1 Like

Thats what I was saying. You should do that.

I know that it is possible, but it is unlikely.

Accessories can be touched too, and big accessories will give the player a huge disadvantage. It’s better to narrow it down to the limbs or create a static hitbox that follows the root part to keep things consistent and more predictable. This is what most obby games do so your moving limbs don’t interfere as much with your ability to dodge things that can kill you.

in that case

	if hit:FindFirstAncestorWhichIsA("Accessory") then
		return
	end	

would probably cover that case