Damage not working

And the part doesnt get deleted until it hits, so this is very confusing

2 Likes

Why don’t you try this?

local Part
local canHit = true

Part.Touched:Connect(function(hit)
	if not hit or hit.Parent or hit:FindFirstChild("Humanoid") then
		return
	end
	
	if game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) then
		return
	end
	
	if canHit == false then return end
	canHit = false
	
	local basedamage = Part.BaseDamage.Value
	local dmgreduce = hit.Parent:FindFirstChild("DmgReduction").Value
	
	hit.Parent.Humanoid:TakeDamage(basedamage / dmgreduce)
	
	task.wait(10) -- cooldown before if can hit again
	canHit = true
end)
2 Likes
> local CanHit = true
> 
> Part.Touched:Connect(function(Hit)
>     if CanHit == false then return end
>     if game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent) == nil then -- Makes sure it isn't a player
>         local EnemyHumanoid = Hit.Parent:FindFirstChild("Humanoid")
>         if EnemyHumanoid and EnemyHumanoid.Health > 0 then
>             EnemyHumanoid:TakeDamage(20)
>             CanHit = false     
>         end
>     end
> end)
> 
> Part.TouchEnded:Connect(function(Hit)
>     CanHit = true
> end)
2 Likes

Why the need for task.wait(1) before changing canHit = false? Won’t that allow for multiple hits to occur during that 1 second period.

Anyway yeah you can try Indie’s code too. I’m not sure what you are trying to achieve here other than that checks to determine whether a hit part was player or not

2 Likes

Wait, is this essentially like a barricade system?

2 Likes

I figured out that the script doesn’t even work (the one I posted above), some other script was printing the same thing, but I still don’t get how it doesn’t work since it just uses the same script as the other hitboxes I do and those work. Also I tried your script and it is still having issues.

2 Likes

All good, just really quick are you trying to do like a barricade system?

2 Likes

I’ve never heard of a barricade system, what is it?

1 Like

Oh never mind, I had made a barricade system but I’m sure it won’t apply here, okay here is a working script, sorry I wasn’t on Roblox Studio before so I wasn’t sure!

local Part = script.Parent

local CanHit = true

Part.Touched:Connect(function(Hit)
	if CanHit == false then return end

	CanHit = false    

	if game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent) == nil then -- Makes sure it isn't a player
		local EnemyHumanoid = Hit.Parent:FindFirstChild("Humanoid")
		if EnemyHumanoid and EnemyHumanoid.Health > 0 then
			EnemyHumanoid:TakeDamage(20) 
		end
	end
end)

Part.TouchEnded:Connect(function(Hit) -- 
	CanHit = true
end)
1 Like

Keep in mind this will only damage the enemy once, once they touch the part, did you want it like them consistently getting damaged?

1 Like

I only wanted it to damage them one. Also, I tried some stuff and when I deleted the line finding dmg reduction & removing the player identification line it damaged me but not the dummy. It should’ve damaged both of us but it didn’t so the problem might be the part won’t touch the dummy for some reason

1 Like

Did you try my script? It should work?

1 Like

I tried it and it should work but the main problem is that the part won’t touch the dummies, which makes no sense because CanTouch is true and it is able to touch the player when you remove the player line

1 Like

Did you make sure the enemy’s parts and I mean every single part inside of the enemy has CanCollide on

1 Like

Yeah they are all can collide on

Okay well it clearly not the code, can you send a picture of the enemy’s character model opened?

image
All parts are collide on

Maybe try debugging again? Try printing out Hit.Name and Hit.Parent.Name see what you get!

print(“hit them fr”)

I"M DEAD :rofl:

So after a while I fixed it; the problem was that the dummies were anchored which I didn’t think would be an issue but was the problem