Script Damaging For No Reason

Here’s the entire script, after touching the radius once, it continuously damages the player even after they’ve left. Also completely ignores debounce. (Script is messy cause I was desperate to fix)

db=false
script.Parent.Touched:Connect(function(part)
	for i,v in pairs(script.Parent:GetTouchingParts()) do

		if v:IsA("Part") or v:IsA("UnionOperation") or v:IsA("MeshPart") or v:IsA("TrussPart") and db==false then
			if v.Parent and v.Parent:FindFirstChild("Humanoid") and db==false then
				if v.Parent~=script.Parent.Parent and db==false then
					if v.Parent:FindFirstChild("CharacterInfo") and v.Parent:FindFirstChild("CharacterInfo").AOTstuff.IsTitan.Value==false  then
						if db==false then
							damage(v)
							print("damaged" .. v.Name)
						end
					end
				end	
			else
				if v.Parent and v.Parent~=game.Workspace.Baseplate and v.Parent~=game.Workspace.UnUnanchorables and v.Parent.Parent~=game.Workspace.UnUnanchorables then
					v.Anchored=false
					db=true
					task.wait(.5)
					db=false
				end
			end	
		end
	end

end)

function damage(target)
	target.Parent.Humanoid:TakeDamage(1)
	task.wait(.5)
	db=false
end

The Forum won’t let me upload the video of it :man_shrugging:

1 Like

First off, you are checking if db == false 4 times for no reason. Second, assuming this get the player’s characters, only checking for if the touched part’s parent has a Humanoid is enough. Also, can you explain the script a bit more, what exactly it does?

1 Like
if db==false then
  db=true
  damage(v)
  print("damaged" .. v.Name)
end

you forgot to change the db when damaged

1 Like

I checked for db 4 times because it kept bugging lol. The script is supposed to damage humanoids inside the radius and unanchor parts it touches (the reason why i check for v being a part, union, or mesh) The unanchoring works fine, its just the damage thats bugging out

Just do a rewrite at this point, to clean up the code a bit

Whenever I put on a normal debounce the script doesn’t work at all???

I rewrote your code using the conditions from the old code. Could you test it?

local Tick = 0
local CooldownTime = .5

local DAMAGE = 1

script.Parent.Touched:Connect(function(Part)
	if Tick - tick() < CooldownTime then return end
	if not Part:IsA("BasePart") or not Part.Parent then return end

	if Part.Parent:FindFirstChild("Humanoid") then
		local Character = Part.Parent
		
		if Character == script.Parent.Parent then return end
		if not Character:FindFirstChild("CharacterInfo") or Character.CharacterInfo.AOTstuff.IsTitan then return end
		
		Character.Humanoid:TakeDamage(DAMAGE)
		
		Tick = tick()
	else
		if Part.Parent == workspace.Baseplate then return end
		if Part.Parent == workspace.UnUnanchorables then return end

		Part.Anchored = false

		Tick = tick()
	end
end)
2 Likes

Thanks for taking the time to make this, weirdly enough though, my character doesn’t take any damage at all. Im pretty sure its a bug on roblox’s end as simple debounces didn’t work.

1 Like

I was reading this post from a while ago, the problem roots from putting delays in a for loop. When i turn on the debounce it just waits till the debounce is over then continues damaging each part it touches.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.