And the part doesnt get deleted until it hits, so this is very confusing
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)
> 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)
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
Wait, is this essentially like a barricade system?
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.
All good, just really quick are you trying to do like a barricade system?
I’ve never heard of a barricade system, what is it?
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)
Keep in mind this will only damage the enemy once, once they touch the part, did you want it like them consistently getting damaged?
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
Did you try my script? It should work?
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
Did you make sure the enemy’s parts and I mean every single part inside of the enemy has CanCollide
on
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?
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
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