So i made a boss fight where you have to position yourself so that when the enemy summons a spike, it impales itself dealing damage but if you get hit by it, you take damage.
The issue here is that damaging players working but damaging itself is not
I don't understand why it's not.
there is a value called HP inside the enemy model the script is inside the enemy model spike is defined as the summoned spike earlier in the code which works fine
Code:
local hit = false local behit = false spike.Touched:Connect(function(part) if game.Players:FindFirstChild(part.Parent.Name) then if hit == false then hit = true part.Parent.Humanoid.Health = part.Parent.Humanoid.Health - (15+(level*5)) end end if part.Parent == script.Parent then if behit == false then behit = true script.Parent.HP.Value = script.Parent.HP.Value - math.random(50,750) end end end)
Issue has been resolved, check comments to see how.
you clarified some of your variables wrong, look at this and read the messages inside the script which will show you what you did wrong
local hit = true --was false before local behit = false level = 0 --you might wanna remove this idk spike = nil--put location of spike here spike.Touched:Connect(function(part) if game.Players:FindFirstChild(part.Parent.Name) then if hit == false then --again, you just called out hit false in the script you showed us, make it true, when it damages make it go false so there's no damage flooding. hit = false --was true before, make hit flaseright aftet it hits, so this functioon cant be flooded like i sayed. part.Parent:FindFirstChild("Humanoid").Health = part.Parent:FindFirstChild("Humanoid").Health - 15+level*5 end end if part.Parent == script.Parent then if behit == false then behit = true script.Parent.HP.Value = script.Parent.HP.Value - math.random(50,750) end end end)
you might want to edit a lot of stuff I just send above since I don't know half of what's going on here, do that correctly and it will work as you want it to.