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 4 years ago

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

01local rarm = script.Parent:FindFirstChild('Right Arm') or script.Parent:FindFirstChild('RightUpperArm')
02local larm = script.Parent:FindFirstChild('Left Arm') or script.Parent:FindFirstChild('LeftUpperArm')
03local head = script.Parent:FindFirstChild("Head")
04 
05local debounce = false
06 
07local function dmg(hit)
08    if (hit.Parent ~= nil) and (not debounce) then
09        debounce = true
10        local hum = hit.Parent:FindFirstChild('Humanoid')
11        if (hum ~= nil) then
12            hum.Health -= 200
13        end
14        wait(1)
15        debounce = false
View all 21 lines...

2 answers

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

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

1local 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:

1if 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:

01local rarm = script.Parent:FindFirstChild('Right Arm') or script.Parent:FindFirstChild('RightUpperArm')
02local larm = script.Parent:FindFirstChild('Left Arm') or script.Parent:FindFirstChild('LeftUpperArm')
03local head = script.Parent:FindFirstChild("Head")
04 
05local debounce = false
06 
07local function dmg(hit)
08    if (hit.Parent ~= nil) and (not debounce) and (not hit.Parent.Name == "noobs") then
09        debounce = true
10        local hum = hit.Parent:FindFirstChild('Humanoid')
11        if (hum ~= nil) then
12            hum.Health -= 200
13        end
14        wait(1)
15        debounce = false
View all 21 lines...
0
where did i run it ? batmath62 5 — 4y
0
where did i run it ? batmath62 5 — 4y
0
You can add it to line 8, if (hit.Parent ~= nil) and (not debounce) and (not hit.Parent.Name == "noobs" then spacefighterboss 0 — 4y
0
and then he never marked the solution RunKittenzRComin 170 — 4y
View all comments (3 more)
0
can you please re do the script i dont understand batmath62 5 — 4y
0
ok spacefighterboss 0 — 4y
0
its work but the noob still follow the other batmath62 5 — 4y
Ad
Log in to vote
0
Answered by 4 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...

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

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 — 4y
0
where did i run this script ? batmath62 5 — 4y

Answer this question