So I am making a tower defense game following a pretty good tutorial. I tweak some code on what the tutorial was doing and when I run this code, it clones only a little then what it is suppose to be. Can anyone help me on this? thanks
Script:
wait(10)
local spawnTime = .6
local spawnRate = 1
local wave = script.Parent.wave
local module = require(script.ModuleScript)
local pS = game:GetService("PhysicsService")
pS:CreateCollisionGroup("Minions")
pS:CreateCollisionGroup("Mini")
pS:CreateCollisionGroup("walls")
pS:CollisionGroupSetCollidable("Minions", "Minions", false)
pS:CollisionGroupSetCollidable("Mini", "walls", true)
local maxSpawn = script.Parent.maxSpawn
local spawnUnits = script.Parent.spawnedUnits
while script.Parent.Base.HP.Value ~= 0 do
wait(spawnTime)
local destroyedUnits = script.Parent.destroyedUnits
for i = 1, math.huge do
wait()
local bloons = game:GetService("ReplicatedStorage").Minions:GetChildren()[math.random(1, # game:GetService("ReplicatedStorage").Minions:GetChildren())]:Clone()
if spawnUnits.Value ~= maxSpawn then
for i1, v1 in pairs(module.Wave) do
if i1 == wave.Value then
for i2, v2 in pairs(v1) do
if bloons.Name == i2 then
maxSpawn.Value = v2
destroyedUnits.Value = v2
bloons.Parent = script.Parent.Minions
end
end
end
end
end
wait()
spawnUnits.Value = spawnUnits.Value + 1
for i, v in pairs(bloons:GetChildren()) do
if v:IsA("MeshPart") or v:IsA("Part") then
pS:SetPartCollisionGroup(v, "Minions")
pS:SetPartCollisionGroup(v, "Mini")
for i1, v1 in pairs(script.Parent.walls:GetChildren()) do
if v1:IsA("Part") then
pS:SetPartCollisionGroup(v1, "walls")
end
end
end
end
local anim = script.Floating
--bloons:WaitForChild("Humanoid"):LoadAnimation(anim):Play()
bloons.HumanoidRootPart.CFrame = script.Parent.Spawn.CFrame
local pFS = game:GetService("PathfindingService")
spawn(function()
for _, waypoint in pairs(script.Parent.Waypoints:GetChildren()) do
local path = pFS:CreatePath()
path:ComputeAsync(bloons.HumanoidRootPart.Position, waypoint.Position)
local wp = path:GetWaypoints()
for _, wp2 in pairs(wp) do
bloons.Humanoid:MoveTo(wp2.Position)
bloons.Humanoid.MoveToFinished:Wait()
end
end
script.Parent.Base.HP.Value = script.Parent.Base.HP.Value - 1
script.Parent.Base.Sound:Play()
bloons:Destroy()
script.Parent.Minions.DescendantRemoving:Connect(function()
destroyedUnits.Value = destroyedUnits.Value - 1
end)
end)
if spawnUnits.Value == maxSpawn.Value or destroyedUnits.Value == 0 then
spawnUnits.Value = 0
wave.Value = wave.Value + 1
wait()
end
end
end
Module script:
local module = {
Wave = {
[1] = {["RedPops"] = 5}}
}
return modul