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

My attack doesn't damage all humanoid?

Asked by 3 years ago

Wow, I have been asking a lot of questions. Anyways, I have been making a game like Dungeon Quest, but for some reason the damage doesn't work. It damages the users, but not the bots, which is a big issue for me.

This is the touched function, triggering it so it hurts the bot, but it hurts the player and not the bot.

bomb.Touched:Connect(function(hit)
            local debounceTwo = false
            if hit ~= player.Character then
                if hit == player.Character.Torso then
                    if debounceTwo == false then
                        print("Before Damage")
                        debounceTwo = true
                        hit.Parent.Humanoid:TakeDamage(50)
                        wait(3)
                        debounceTwo = false
                        print("Taken Damage")
                    end
                end
            end
        end)

1 answer

Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
3 years ago

Sound like your script might be breaking when one of your bots dies, so it will cause an error

a way i would fix this bug is to do something like this...

bomb.Touched:Connect(function(hit)
            local debounceTwo = false
            if hit ~= player.Character then
                if hit == player.Character.Torso then
                    if debounceTwo == false then
            if(hit.Parent == nil) then return end -- if the parent of hit is nil or just got deleted then simply stop executing further
                        print("Before Damage")
                        debounceTwo = true
            local Humanoid =  hit.Parent:FindFirstChildOfClass("Humanoid")
            if(Humanoid ~= nil) then
                           Humanoid:TakeDamage(50)
                            wait(3)
                print("Taken Damage")
            end
                        debounceTwo = false

                    end
                end
            end
        end)

Just a thought, I've written in the past a Humanoid Finder and i thought id share it here since its kinda relevant to this problem

The code is here:

function findHumanoidin(model)
    local List = model:GetDescendants()
    local Found = nil
    for k,v in pairs(List) do
        if(v:IsA("Humanoid") == true) then
            Found = v
        end
    end
    return Found, Found:GetFullName()
end
--// how to call the function
local NPC = workspace["NP-C 9000 Robot"]
local Humanoid, Location = findHumanoidin(NPC)
print(NPC.Name," Has ",(Humanoid ~= nil and " A " or " No ").." Humanoid"..(Humanoid ~= nil and " Located in ["..Location.."] " or ""))

Ad

Answer this question