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

i am unsure how to make my script select the correct zombie npc, can you help?

Asked by 3 years ago

i have tried using GetChildren however it doesn't work

local serverstorage = game:GetService("ServerStorage")
local replicatedstorage = game:GetService("ReplicatedStorage")
local zombie =  serverstorage:WaitForChild("zombie")
local pl = game:GetService("Players")
local p = pl:GetPlayers()

while wait(1) do
    if #game.Workspace.zombies:GetChildren() == 0 then
        for i =0 , _G.dead, 1 do
            local zom = zombie:Clone()
            local me = game.Workspace[tostring(_G.pl[math.random(1,#_G.pl)])]

            zom.Parent = game.Workspace.zombies
            zom:SetPrimaryPartCFrame(me.HumanoidRootPart.CFrame * CFrame.new(math.random(1,100),10,math.random(1,100)))
            local npc = game.Workspace.zombies:WaitForChild("zombie")
            local RunAnim = npc.Zombie.runanim

            local loadrun = npc.Zombie:LoadAnimation(RunAnim)


            loadrun:Play()


        end
    end
end 



how can i make it so that the animation plays on the zombie that i just spawned not the first in the folder?

2 answers

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago

Your newly spawned zombie is stored in the zom variable, load animation on it.

local zom = zombie:Clone()
local me = game.Workspace[tostring(_G.pl[math.random(1,#_G.pl)])]

zom.Parent = game.Workspace.zombies
zom:SetPrimaryPartCFrame(me.HumanoidRootPart.CFrame * CFrame.new(math.random(1,100),10,math.random(1,100)))
--local npc = game.Workspace.zombies:WaitForChild("zombie")
local RunAnim = zom.Zombie.runanim

--local loadrun = zom.Zombie:LoadAnimation(RunAnim)
local loadrun = zom.Zombie.Animator:LoadAnimation(RunAnim)


loadrun:Play()

Note that I used zom.Zombie.Animator:LoadAnimation() instead of zom.Zombie:LoadAnimation(), this is because LoadAnimation on Humanoid is deprecated and should not be used for new work, see this post for details.

Ad
Log in to vote
0
Answered by 3 years ago

i am so great full to imKirda, you have fixed my problem with only 2 lines of code i truly appreciate it

Answer this question