Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My attack doesn't damage all humanoid?

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

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 ""))

This discussion is preserved as it was. New answers, comments, and votes are closed.