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:
01 | local hit = false |
02 | local behit = false |
03 | spike.Touched:Connect( function (part) |
04 | if game.Players:FindFirstChild(part.Parent.Name) then |
05 | if hit = = false then |
06 | hit = true |
07 | part.Parent.Humanoid.Health = part.Parent.Humanoid.Health - ( 15 +(level* 5 )) |
08 | end |
09 | end |
10 | if part.Parent = = script.Parent then |
11 | if behit = = false then |
12 | behit = true |
13 | script.Parent.HP.Value = script.Parent.HP.Value - math.random( 50 , 750 ) |
14 | end |
15 | end |
16 | 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
01 | local hit = true --was false before |
02 | local behit = false |
03 | level = 0 --you might wanna remove this idk |
04 | spike = nil --put location of spike here |
05 | spike.Touched:Connect( function (part) |
06 | if game.Players:FindFirstChild(part.Parent.Name) then |
07 | 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. |
08 | hit = false --was true before, make hit flaseright aftet it hits, so this functioon cant be flooded like i sayed. |
09 | part.Parent:FindFirstChild( "Humanoid" ).Health = part.Parent:FindFirstChild( "Humanoid" ).Health - 15 +level* 5 |
10 | end |
11 | end |
12 | if part.Parent = = script.Parent then |
13 | if behit = = false then |
14 | behit = true |
15 | script.Parent.HP.Value = script.Parent.HP.Value - math.random( 50 , 750 ) |
16 | end |
17 | end |
18 | 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.