You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? I want to make a part where when touched/entered it slows you down and you get damaged over time but when leaving it speeds you back up and the damaging stops
-
What is the issue?
What Happens When The Hitboxes are collided there is also a chance you will keep taking damage after leaving the hitbox
The Effect I Want
-
What solutions have you tried so far? I did but none have catered to what I am trying to accomplish or address my issue directly
local getall = workspace:GetDescendants()
local cooldown = {}
local barbed = {}
local function damage(hit,barb)
for i,v in pairs(workspace:GetPartsInPart(barb)) do
if v.Parent:FindFirstChild("Humanoid") then
local humanoid = v.Parent.Humanoid
if not table.find(barbed,humanoid) then
table.insert(barbed,v.Parent.Humanoid)
v.Parent.Humanoid.WalkSpeed = 1
wait(1)
cooldown[v.Parent.Name] = true
end
end
end
end
for i,barb in pairs(getall) do
if barb.Name == "Barb" then
barb.Touched:Connect(function(hit)
damage(hit,barb)
end)
barb.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if cooldown[hit.Parent.Name] == true then
hit.Parent.Humanoid.WalkSpeed = 16
table.remove(barbed,table.find(barbed,hit.Parent.Humanoid))
cooldown[hit.Parent.Name] = nil
end
end
end)
end
end
while true do
wait(1)
for i,v in pairs(barbed) do
v:TakeDamage(10)
end
end