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

my zombies named "noobs" attacking each others?

hi i need help please my zombies named "noobs" attacking each others here is the script

local rarm = script.Parent:FindFirstChild('Right Arm') or script.Parent:FindFirstChild('RightUpperArm')
local larm = script.Parent:FindFirstChild('Left Arm') or script.Parent:FindFirstChild('LeftUpperArm')
local head = script.Parent:FindFirstChild("Head")

local debounce = false 

local function dmg(hit) 
	if (hit.Parent ~= nil) and (not debounce) then 
		debounce = true 
		local hum = hit.Parent:FindFirstChild('Humanoid')
		if (hum ~= nil) then
			hum.Health -= 200
		end
		wait(1) 
		debounce = false 
	end
end

rarm.Touched:Connect(dmg) 
larm.Touched:Connect(dmg) 
head.Touched:Connect(dmg)

2 answers

Hi, when function dmg() is run, it checks hit.Parent for humanoid:


local hum = hit.Parent:FindFirstChild('Humanoid')

Your zombies likely have humanoids in them, so they pass the check. You should make another if statement such as:

if not hit.Parent.Name == "noobs" then -- or whatever the zombie name is

to make sure it doesn't run if it hits another zombie. This assumes you want to damage any humanoid. If it's just players, use DeceptiveCaster's solution.

Edit:

local rarm = script.Parent:FindFirstChild('Right Arm') or script.Parent:FindFirstChild('RightUpperArm')
local larm = script.Parent:FindFirstChild('Left Arm') or script.Parent:FindFirstChild('LeftUpperArm')
local head = script.Parent:FindFirstChild("Head")

local debounce = false 

local function dmg(hit) 
    if (hit.Parent ~= nil) and (not debounce) and (not hit.Parent.Name == "noobs") then 
        debounce = true 
        local hum = hit.Parent:FindFirstChild('Humanoid')
        if (hum ~= nil) then
            hum.Health -= 200
        end
        wait(1) 
        debounce = false 
    end
end

rarm.Touched:Connect(dmg) 
larm.Touched:Connect(dmg) 
head.Touched:Connect(dmg)

7 comments

0

where did i run it ?

0

where did i run it ?

0

You can add it to line 8, if (hit.Parent ~= nil) and (not debounce) and (not hit.Parent.Name == "noobs" then

0

and then he never marked the solution

0

can you please re do the script i dont understand

0

ok

0

its work but the noob still follow the other

Players:GetPlayerFromCharacter()

GetPlayerFromCharacter() is a function of the Players service that returns a Player object associated with the given Instance, given that there is a client associated with the Instance. If no Player object can be obtained from the Instance, the function returns nil.

This is extremely useful for zombie AI and you should absolutely use it (I use it myself). You have to counteract the function, such as doing...

local inst = script.Parent
if not game:GetService("Players"):GetPlayerFromCharacter(inst) then
	print("No player")
else
	print("There is a player here")
end

not will essentially check if the function does not return a player; this is equivalent to false, and in this case it refers to not true, which is the same exact thing.

2 comments

0

where did i run this script ?

0

where did i run this script ?

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