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.
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