I need help with my script for a barbwire effect

You can write your topic however you want, but you need to answer these questions:

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

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

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

Try using raycasting, .Touched event isnt that great for your situation.

Maybe try making a Region3 to check if the player is colliding with it.

How would this work would I raycast from the character?

How would I go about controlling multiple region3’s with one script?

Loop through each Region3 and FindPartsInRegion3.

1 Like

oh noononono, you raycast from the edge of the barbwire effect.

1 Like