local val = game.ReplicatedStorage.numberval.Value for i = 1,10 do game.ReplicatedStorage.bacteria:Clone() game.ReplicatedStorage.bacteria:Clone().Parent = workspace game.ReplicatedStorage.bacteria:Clone().HumanoidRootPart.Position = Vector3.new(math.random(-315.026, -268.827),-148.634, 2.76) print("spawned 1wave") wait() end while true do if val == 10 then for i = 1,10 do game.ReplicatedStorage.bacteria:Clone() game.ReplicatedStorage.bacteria:Clone().Parent = workspace game.ReplicatedStorage.bacteria:Clone().HumanoidRootPart.Position = Vector3.new(math.random(-315.026, -268.827),-148.634, 2.76) print("spawned 2wave") wait() val = val + 1 end elseif val == 30 then for i = 1,10 do game.ReplicatedStorage.bacteria:Clone() game.ReplicatedStorage.bacteria:Clone().Parent = workspace game.ReplicatedStorage.bacteria:Clone().HumanoidRootPart.Position = Vector3.new(math.random(-315.026, -268.827),-148.634, 2.76) print("spawned 3wave") wait() end elseif val == 40 then for i = 1,10 do game.ReplicatedStorage.bacteria:Clone() game.ReplicatedStorage.bacteria:Clone().Parent = workspace game.ReplicatedStorage.bacteria:Clone().HumanoidRootPart.Position = Vector3.new(math.random(-315.026, -268.827),-148.634, 2.76) print("spawned 4wave") wait() end elseif val == 50 then for i,v in pairs(game.Workspace:GetChildren()) do if v.Name == "bacteria" and v.Humanoid then v:remove() print("removed waste.....") end end end wait(0.1) end
Does not print anything but print("spawned wave1") Im trying to make "zombie" waves. Im not sure what the error is. No errors are shown in output And whenever a zombie is killed it adds 1 to the value, Ive checked the value succesfully changes to 10 after all the zombies are killed. So i dont know what to do
Firstly, variables do not store references to properties: they will just store the value of the property at the time of declaration and be constant throughout your code. Secondly, calling the :Clone()
function will always create a new clone, not like it references the previously cloned part. Lastly, given that its a number value, you should use a Changed
event instead of a while loop. Here's the fixed code along with some adjustments
local val = game.ReplicatedStorage.numberval function SpawnWave() for i = 1, 10 do local clone = game.ReplicatedStorage.bacteria:Clone() clone.HumanoidRootPart.CFrame = CFrame.new(math.random(-315.026, -268.827),-148.634, 2.76) clone.Parent = workspace end end SpawnWave() val.Changed:Connect(function() if math.floor(val.Value / 10) == (val.Value / 10) and val.Value < 50 then SpawnWave() elseif val.Value == 50 then for i,v in pairs(game.Workspace:GetChildren()) do if v.Name == "bacteria" and v:FindFirstChild("Humanoid") then v:Destroy() print("removed waste.....") end end end end)