So I am making a COD zombies game on roblox and I got everything to work except I want it to spawn zombies to go to a barricade. I already got that to work but then I want to randomize the barricades and only go to barricades when the room is opened. I already made a script for it but it doesn’t work the zombies just spawn in 1 place and don’t even move.
local Humanoid = script.Parent.Humanoid
-- local Barriace = workspace.Map.Barricades.Barricade1.Barricademain
-- local WalkPoints = workspace.Barricades.Barricade1.Walkpoints
local Attacking = script.Parent.AttackingBarricade
function walkTo(SelectedPoint)
local Sel = SelectedPoint
Humanoid:MoveTo(SelectedPoint.Position)
Humanoid.MoveToFinished:Wait()
end
--A function to move the NPC to a selected point
Humanoid.Died:Connect(function()
Attacking.Value = false
end)
--Stop attacking when dead
spawn(function()
for i,v in pairs(workspace.Map:GetChildren()) do
if v:IsA("BoolValue") then
if v.Value == true then
local Barricades = v.Parent.Barricades:GetChildren()
local Barriace = Barricades[math.random(1, # Barricades)]
local WalkPoints = Barriace.Walkpoints
local animation = Humanoid:LoadAnimation(script.Parent.Attack)
walkTo(WalkPoints.Point1)
walkTo(WalkPoints.Point2)
walkTo(WalkPoints.Point3)
walkTo(WalkPoints.Point4)
--walk
Attacking.Value = true
while wait(2) do
--[[
This loop basically checks if the barricades health is above 0
If the health is not above 0 the real zombie will be moved into the play space.
]]
if Attacking.Value then
if Barriace.Dead.Value == false then --check if barricade is alive
animation:Play()
wait(0.5)
Barriace.Health.Value = Barriace.Health.Value - 10
else
local cloneZombie = game.ReplicatedStorage.Zombie:Clone() --create a clone of the actual zombie
cloneZombie.Parent = workspace
cloneZombie.HumanoidRootPart.CFrame = WalkPoints.SpawnPoint.CFrame
cloneZombie.Humanoid.Health = Humanoid.Health
script.Parent:Destroy()
break
end
end
end
end
end
end
end)