How can a killbrick do damage while the player isnt moving

I want to make a flood system with just tween and a killscript

If I stand in the flood space without moving, i won’t be damaged

I don’t know what kind of event has this where you still get damaged while you’re standing still
Heres this script i have in the flood part

local part = script.Parent
local db= false
part.Touched:Connect(function(p)
	if db == false then
		db = true
		local h= player.Parent:FindFirstChild("Humanoid")
		if h ~= nil then
			player.Parent.Humanoid.Health = player.Parent.Humanoid.Health - 10
			wait(1)
		end
		db = false
	end
end)
1 Like

The touched event only fires when a part is first “touched” on its outer-facing faces by another outer-facing-face with the physics system, from experience. So standing still won’t physically touch the outer faces if the parts don’t physically interact, which would be the case if the flood brick is being resized or CFramed through the player.

It follows then that one way that this could be fixed is if you make the flood part physically interact with the player standing still. I think one way you could do this is by using part velocity or bodyvelocity or some equivalent to move the flood part instead.

However, another approach could be to use a simple for loop with math (assuming the part is rectangular), on all the players humanoidRootParts. You can loop through players who could potentially be in the flood or affected by it, and then use some math to calculate whether their HumanoidRootPart is within the rectangular flood block. This method should be performant enough to run every physics update, which might not be true for region3 (but I’m not sure).

Similarly, an easier implementation could use FindPartsInRegion3WithWhiteList.

Probably the easiest way would be to use GetTouchingParts() on the flood block, but I think this would be the most performance-intensive out of all of the methods.

2 Likes

I think this is the problem

local h= player.Parent:FindFirstChild("Humanoid")

Try change to this

local h= p.Parent:FindFirstChild("Humanoid")
1 Like

You can use this condition -
(‘p’ is the part that is touched)

--check if player is standing still
if p.Parent:FindFirstChild("Humanoid") and p.Parent.Humanoid.MoveDirection.Magnitude == 0 then 
	p.Parent.Humanoid:TakeDamage(100);
end
1 Like