Hello,
I am making a Tower Defence game but I cant get the AI to shoot at random enemies as they all just shoot at one then when that one dies they all switch the the next enemy in the workspace.
local FireRate = 1
while wait(FireRate) do
local Model = script.Parent
local Zombie = workspace:WaitForChild("Normal")
local value = script.Parent:WaitForChild("plrName")
Model:SetPrimaryPartCFrame(CFrame.new(
Model.PrimaryPart.Position,
Zombie.HumanoidRootPart.Position * Vector3.new(1,0,1) +
Model.PrimaryPart.Position * Vector3.new(0,1,0)
))
Zombie:WaitForChild("Health").Value = Zombie:WaitForChild("Health").Value - 1
game.Players:WaitForChild(value.Value).Cash.Value = game.Players:WaitForChild(value.Value).Cash.Value + 1
script.Parent.Shoot:Play()
script.Parent.Muzzle.BillboardGui.Enabled = true
script.Parent.Muzzle1.BillboardGui.Enabled = false
wait(0.1)
script.Parent.Muzzle1.BillboardGui.Enabled = true
script.Parent.Muzzle.BillboardGui.Enabled = false
wait(0.1)
script.Parent.Muzzle1.BillboardGui.Enabled = false
wait(0.24)
local Model = script.Parent
local Zombie = workspace:WaitForChild("Normal")
local value = script.Parent.plrName
Model:SetPrimaryPartCFrame(CFrame.new(
Model.PrimaryPart.Position,
Zombie.HumanoidRootPart.Position * Vector3.new(1,0,1) +
Model.PrimaryPart.Position * Vector3.new(0,1,0)
))
Zombie:WaitForChild("Health").Value = Zombie:WaitForChild("Health").Value - 1
game.Players:WaitForChild(value.Value).Cash.Value = game.Players:WaitForChild(value.Value).Cash.Value + 1
script.Parent.Shoot:Play()
script.Parent.Muzzle.BillboardGui.Enabled = true
script.Parent.Muzzle1.BillboardGui.Enabled = false
wait(0.1)
script.Parent.Muzzle1.BillboardGui.Enabled = true
script.Parent.Muzzle.BillboardGui.Enabled = false
wait(0.1)
script.Parent.Muzzle1.BillboardGui.Enabled = false
end
Thanks.
