How to make it where when a player reaches a certain speed they die

I’m trying to make it where when a player is in an area and if they stop in that area then they die.

local SlowPart = workspace.SlowPart

function getHumanoidsTouching()
	local parts = workspace:GetPartsInPart(SlowPart) 
	local found = {} 
	for i, part in pairs(parts) do 
		local char = part.Parent 
		local hum = char:FindFirstChild("Humanoid") 
		if hum and not table.find(found, hum) then 
			table.insert(found, hum)
		end
	end
	return found 
end

while task.wait(1) do 
	local humanoids = getHumanoidsTouching() 
	for i, humanoid in pairs(humanoids) do 
		if humanoid.WalkSpeed >= 0 then
			humanoid.Health = 0
		end
	end
end

Here is what I have so far and it doesn’t seem to be working. When a player is in an area or interacting with a part and the script detects that there walk speed is 0 then that player will die. So far what is happening is when the player interacts with the part the script will kill them no matter what their walk speed is. Thanks you.

>= means greater or equal to so if the humanoid has more than 0 walkspeed it will set their Health to 0, you should change

to

if humanoid.WalkSpeed <= 0 then
1 Like

What exactly do you mean by walkspeed? Do you mean if they stop moving even if they can still move or the Humanoid.WalkSpeed property?

Walkspeed does not determine the speed of a character. Instead, use Humanoid.MoveDirection.Magnitude

local SlowPart = workspace.SlowPart

function getHumanoidsTouching()
	local parts = workspace:GetPartsInPart(SlowPart) 
	local found = {} 
	for i, part in pairs(parts) do 
		local char = part.Parent 
		local hum = char:FindFirstChild("Humanoid") 
		if hum and not table.find(found, hum) then 
			table.insert(found, hum)
		end
	end
	return found 
end

while task.wait(1) do 
	local humanoids = getHumanoidsTouching() 
	for i, humanoid in pairs(humanoids) do 
		if humanoid.MoveDirection.Magnitude <= 0 then
			humanoid.Health = 0
		end
	end
end

This should work. Let me know if this helps :slight_smile:

2 Likes