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 4 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.

01bomb.Touched:Connect(function(hit)
02            local debounceTwo = false
03            if hit ~= player.Character then
04                if hit == player.Character.Torso then
05                    if debounceTwo == false then
06                        print("Before Damage")
07                        debounceTwo = true
08                        hit.Parent.Humanoid:TakeDamage(50)
09                        wait(3)
10                        debounceTwo = false
11                        print("Taken Damage")
12                    end
13                end
14            end
15        end)

1 answer

Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
4 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...

01bomb.Touched:Connect(function(hit)
02            local debounceTwo = false
03            if hit ~= player.Character then
04                if hit == player.Character.Torso then
05                    if debounceTwo == false then
06            if(hit.Parent == nil) then return end -- if the parent of hit is nil or just got deleted then simply stop executing further
07                        print("Before Damage")
08                        debounceTwo = true
09            local Humanoid =  hit.Parent:FindFirstChildOfClass("Humanoid")
10            if(Humanoid ~= nil) then
11                           Humanoid:TakeDamage(50)
12                            wait(3)
13                print("Taken Damage")
14            end
15                        debounceTwo = false
16 
17                    end
18                end
19            end
20        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:

01function findHumanoidin(model)
02    local List = model:GetDescendants()
03    local Found = nil
04    for k,v in pairs(List) do
05        if(v:IsA("Humanoid") == true) then
06            Found = v
07        end
08    end
09    return Found, Found:GetFullName()
10end
11--// how to call the function
12local NPC = workspace["NP-C 9000 Robot"]
13local Humanoid, Location = findHumanoidin(NPC)
14print(NPC.Name," Has ",(Humanoid ~= nil and " A " or " No ").." Humanoid"..(Humanoid ~= nil and " Located in ["..Location.."] " or ""))
Ad

Answer this question