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

my zombies named "noobs" attacking each others?

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)
0
where did i run it ? batmath62 5 — 3y
0
where did i run it ? batmath62 5 — 3y
0
You can add it to line 8, if (hit.Parent ~= nil) and (not debounce) and (not hit.Parent.Name == "noobs" then spacefighterboss 0 — 3y
0
and then he never marked the solution RunKittenzRComin 170 — 3y
View all comments (3 more)
0
can you please re do the script i dont understand batmath62 5 — 3y
0
ok spacefighterboss 0 — 3y
0
its work but the noob still follow the other batmath62 5 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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.

0
where did i run this script ? batmath62 5 — 3y
0
where did i run this script ? batmath62 5 — 3y

Answer this question