How would I make it where whenever a player is in a zone they get damaged every second.
I’ve tried something using this script but it only damages the player when they first touch the part, not if they stay inside of the part.
script.Parent.Touched:Connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 5
end
end)
while wait(1) do
if table.find(workspace:GetPartsInPart(workspace.DamagingZone), script.Parent.HumanoidRootPart) then
script.Parent.Humanoid:TakeDamage(5)
end
end
local Players = game:GetService("Players")
local ZoneStart, ZoneEnd = Vector3.new(-10, -10, -10), Vector3.new(10, 10, 10)
local function Zone()
while task.wait(1) do
for Index, Player in pairs(Players:GetPlayers()) do
if Player.Character then
local HumanoidRootPart = Player.Character.HumanoidRootPart
local Humanoid = Player.Character.Humanoid
if HumanoidRootPart and Humanoid then
if HumanoidRootPart.Position >= ZoneStart and HumanoidRootPart.Position <= ZoneEnd then
Humanoid:TakeDamage(10)
end
end
end
end
end
end
task.spawn(Zone)
Yes it caused a difference because when the part was not anchored it glitched its way into the ground. The part was also transparent so I had no idea that it was underground and that I was not actually interacting with it.