Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[Solved] Why is my damage script not damaging the enemy?

Asked by 3 years ago
Edited 3 years ago

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.

0
Any errors in output? NotTheChara 191 — 3y
0
nope mm1678YT 80 — 3y
0
It can't damage the boss completely? NotTheChara 191 — 3y
0
nope, it takes 0 damage but players can take damage mm1678YT 80 — 3y
View all comments (13 more)
0
Where is this script located? A model, the boss, or the spike? NotTheChara 191 — 3y
0
it's inside the boss as stated in the question mm1678YT 80 — 3y
0
Is it possible to show the whole script? It doesn't seem to have any problem here. NotTheChara 191 — 3y
0
the rest of the script works fine, it's this section that has the problem mm1678YT 80 — 3y
0
Try to print something before `if part.Parent == script.Parent then` and after it so we can see where the script stopped. NotTheChara 191 — 3y
0
it seems like it doesn't even register it touching the boss mm1678YT 80 — 3y
0
the touched event does not fire when it touches the boss, confirmed through print statements mm1678YT 80 — 3y
0
Is the spike a model? NotTheChara 191 — 3y
0
it is a meshpart mm1678YT 80 — 3y
0
oh so it's just roblox's dumb touched function mm1678YT 80 — 3y
0
Or you should say it is Roblox MeshPart fault? NotTheChara 191 — 3y
0
ok so i unachored the spike and it actually works fine now. it even gave it a cool falling down animation without it tipping over, now how do i close this question? mm1678YT 80 — 3y

1 answer

Log in to vote
1
Answered by
n_ubo 29
3 years ago

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.

0
that does not fix the issue that i am having, the player damaging works fine but damaging the NPC (2nd half) was not working mm1678YT 80 — 3y
0
Well, level and spike seems to be unlisted here, not something did wrong. Also, `if hit == false then hit = true` is a debounce but you made it false two times so it can't make the effect of debounce. Please ask the asker for more information before answering. NotTheChara 191 — 3y
Ad

Answer this question