Client sided enemy spawning for a defense game. (CODE IS LIKE SUPER UNREADABLE)

So first off, I just want to say that this is NOT MY CODE!!! My friend wrote this and asked me to help him.

Basically he’s making a wave defense game where you defend a base. Unfortunately he has a problem with the spawning being client sided, and for example, if there are 4 players playing the game, quadruple as much enemies will spawn than there should be.

I could not figure this out due to his script being like 1000 lines long and just confusing me, so I hope someone can actually read this.

Here’s the script. It is placed in a TextLabel, parented to a Frame, which is parented to a gui in StarterGui.

---LOCAL---
local CASHGIVE = 0
---- FUNCTIONS ----
function SoldierSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.soldier:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function KommanderBossSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage["K ommander"]:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function StonerBossSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage["stoner"]:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end

function FighterSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.fighter:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function SniperSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.sniper:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function HeavyshooterSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage["heavy shooter"]:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function DistractorSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.distractor:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function BerserkerSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.berserker:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function SpawnerSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.Spawn:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function CarSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.car:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function TruckSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.trucc:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function MinerSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.miner:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function LongarmsSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.longarms:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function SpearStoneSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.spearstone:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function BrimstoneSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.brimstone:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function SmasherSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.smasher:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function AssasinSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.assasin:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function GolemSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.golem:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end
function Talky1()
	for i = 1,#text do
		script.Parent.Text = string.sub(text,1,i)
		script.Sound:Play()
		wait(0.05) -- the time each words get typed in
	end
end
function Talky2()
	for i = 1,#text do
		script.Parent.Text = string.sub(text,1,i)
		script.Sound2:Play()
		wait(0.05) -- the time each words get typed in
	end
end
function GiveCash()
	for i, plrs in ipairs(game.Players:GetPlayers()) do
		plrs.leaderstats.Stone.Value += CASHGIVE
	end
end
-------------------
---- WAVE SYSTEM ----
script.Parent.Parent.Visible = false
game.Workspace.musicfolder.Intermission:Play()
script.Parent.Parent.Parent.intermision.Visible = true
wait(1)
script.Parent.Parent.Visible = true
game.Workspace.musicfolder.Intermission:Stop()
script.Parent.Parent.Parent.intermision.Visible = false
print("WAVE START")
text = "what a nice base you hav thye!"
Talky1()
wait(2)
text = "it wuld be sch a sharme..."
Talky1()
wait(2)
text = "it wuld be sch a sharme if sumone death it!"
Talky1()
wait(2)
text = "minizos, harge!!!"
Talky1()
wait(6)
game.Workspace.musicfolder["wave 1 - 4"]:Play()
script.Parent.Parent.Visible = false
script.Parent.Parent.Parent.wavetext.Text = "wave 1"
script.WAVE:Play()

for i = 1, 20, 1 do
FighterSummon()
wait(2)
end

while true do
	wait(1)
	if workspace.Enemies:FindFirstChild("fighter") then
		
	else
		print("WAVE ENDED")
		CASHGIVE = 100
		GiveCash()

		script.Parent.Parent.Parent.WAVEEND.Visible = true
		wait(3)
		script.Parent.Parent.Parent.WAVEEND.Visible = false

		script.Parent.Parent.Visible = true

		text = "huh, wuh??"
		Talky1()
		wait(2)
		text = "uzles!1 al of u!!1"
		Talky1()
		wait(2)
		text = "i' higher assasin!!11!11"
		Talky1()
		wait(2)
		text = "thyre btter becuz i say so!"
		Talky1()
		
		wait(4.5)
		script.Parent.Parent.Parent.wavetext.Text = "wave 2"
		script.WAVE:Play()

		script.Parent.Parent.Visible = false
		for i = 1, 14, 1 do
			FighterSummon()
			wait(2)
		end
		for i = 1, 6, 1 do
			AssasinSummon()
			wait(4)
		end
		for i = 1, 8, 1 do
			FighterSummon()
			wait(2)
		end
		AssasinSummon()
		AssasinSummon()
		AssasinSummon()
		AssasinSummon()


		while true do
			wait(1)
			if workspace.Enemies:FindFirstChild("fighter") then

			else
				print("WAVE ENDED")
				CASHGIVE = 200
				GiveCash()
				script.Parent.Parent.Parent.WAVEEND.Visible = true
				wait(3)
				script.Parent.Parent.Parent.WAVEEND.Visible = false

				script.Parent.Parent.Visible = true

				text = "grrrr"
				Talky1()
				wait(1)
				text = "stop tisting my nother word for aiting!"
				Talky1()
				wait(2)
				text = "go go stoned ppl!!1!1"
				Talky1()
				
				wait(5)
				script.Parent.Parent.Visible = false
				script.WAVE:Play()

				script.Parent.Parent.Parent.wavetext.Text = "wave 3"

				for i = 1, 16, 1 do
					FighterSummon()
					wait(0.4)
					AssasinSummon()
					wait(0.4)
				end
				for i = 1, 6, 1 do
					SmasherSummon()
					wait(2)
					AssasinSummon()
					wait(0.8)
					FighterSummon()
					wait(1)
				end
				FighterSummon()
				FighterSummon()
				FighterSummon()
				FighterSummon()
				FighterSummon()
				for i = 1, 5, 1 do
					SmasherSummon()
					wait(1)
				end

				while true do
					wait(1)
					if workspace.Enemies:FindFirstChild("fighter") then
						
					else
						wait(1)
						CASHGIVE = 325
						GiveCash()
						script.Parent.Parent.Parent.WAVEEND.Visible = true
						wait(3)
						script.Parent.Parent.Parent.WAVEEND.Visible = false
						script.Parent.Parent.Visible = true
						text = "a angy!!!"
						Talky1()
						wait(1)
						text = "u noe what????"
						Talky1()
						wait(2)
						text = "deatg sentence!!!!"
						Talky1()
						wait(4.5)

						script.WAVE:Play()
						script.Parent.Parent.Visible = false

						script.Parent.Parent.Parent.wavetext.Text = "wave 4"
						wait(1)
						FighterSummon()
						FighterSummon()
						FighterSummon()
						FighterSummon()
						FighterSummon()
						FighterSummon()

						for i = 1, 4, 1 do
							SmasherSummon()
							wait(1)
							SmasherSummon()
							wait(1)
							SmasherSummon()
							wait(1)
							SmasherSummon()
							wait(1)
							SmasherSummon()
							wait(1)
							GolemSummon()
							wait(10)
							
							for i = 1, 10, 1 do
								FighterSummon()
								wait(0.6)
								AssasinSummon()
								wait(0.6)
							end

						end
						while true do
							wait(1)
							if workspace.Enemies:FindFirstChild("fighter") then
								

							else
								wait(1)
								CASHGIVE = 450
								GiveCash()
								script.Parent.Parent.Parent.WAVEEND.Visible = true
								wait(3)
								game.Workspace.musicfolder["wave 1 - 4"]:Stop()
								script.Parent.Parent.Parent.WAVEEND.Visible = false
								script.Parent.Parent.Visible = true
								script.Parent.Parent["NPC Icon"].Image = "http://www.roblox.com/asset/?id=15403005856"
								text = "am K-ommander..."
								Talky1()
								wait(1)
								text = "and 1 mut k1ll..."
								Talky1()
								wait(2)
								text = "i will kll u so hrd dat u death!!!!11!1!1"
								Talky1()
								wait(4.5)
								game.Workspace.MAP.rain.ParticleEmitter1.Enabled = true
								game.Workspace.MAP.rain.ParticleEmitter2.Enabled = true
								game.Workspace.MAP.rain.ParticleEmitter3.Enabled = true
								game.Workspace.MAP.rain.ParticleEmitter4.Enabled = true
								game.Workspace.MAP.rain.ParticleEmitter5.Enabled = true
								game.Workspace.MAP.rain.ParticleEmitter6.Enabled = true

								game.Workspace.musicfolder["wave special"]:Play()

								script.Parent.Parent.Visible = false

								script.WAVE:Play()

								script.Parent.Parent.Parent.wavetext.Text = "wave 5"
								wait(1)
								SoldierSummon()
								SoldierSummon()
								SoldierSummon()

								for i = 1, 5, 1 do
									SoldierSummon()
									wait(1)
									AssasinSummon()
									wait(1)
									FighterSummon()
									wait(1)
									SmasherSummon()
									wait(1)
								end
								wait(2)
								for i = 1, 3, 1 do
									GolemSummon()
									wait(0.7)
									FighterSummon()
									wait(1.5)
									SoldierSummon()
								end
								wait(2)
								for i = 1, 5, 1 do
									SoldierSummon()
									wait(1)
									AssasinSummon()
									wait(1)
									FighterSummon()
									wait(1)
									SmasherSummon()
									wait(1)
								end
								wait(2)

								for i = 1, 3, 1 do
									GolemSummon()
									wait(0.7)
									SmasherSummon()
									wait(1.5)
									SoldierSummon()
								end
								wait(2)

								for i = 1, 9, 1 do
									AssasinSummon()
									wait(1)
								end
								wait(2)

								for i = 1, 8, 1 do
									AssasinSummon()
									wait(1)
									FighterSummon()
									wait(1)
									SmasherSummon()
									wait(1)
								end
								wait(5)
								SoldierSummon()
								wait(0.3)
								SoldierSummon()
								wait(0.3)
								SoldierSummon()
								wait(0.3)
								SoldierSummon()
								wait(0.3)
								SoldierSummon()
								wait(0.3)
								while true do
									wait(1)
									if workspace.Enemies:FindFirstChild("fighter") then
										
									else
										game.Workspace.musicfolder["wave special"]:Stop()
										wait(3)
										script.Parent.Parent.Visible = true
										text = "am s0 dun,."
										Talky1()
										wait(2)
										text = "nt ev1n minoz harge stp u..."
										Talky1()
										wait(3)
										text = "i will..."
										wait(1)
										Talky1()
										text = "nd 1 belive,,,"
										Talky1()
										wait(1.5)
										script.Parent.Parent.Visible = false
										wait()
										game.Workspace.musicfolder["K-ommander"]:Play()
										text = "am K-ommander..."
										script.Parent.Parent.Parent.wavetext.Text = "K - OMMANDER BOSS"
										Talky1()
										wait(2)
										script.BOSSWAVE:Play()

										SoldierSummon()
										wait(0.1)
										SoldierSummon()
										wait(0.1)
										SoldierSummon()
										wait(0.1)
										SoldierSummon()
										wait(0.1)
										SoldierSummon()
										wait(0.1)
										SoldierSummon()
										wait(0.1)
										SoldierSummon()
										wait(0.1)
										SoldierSummon()
										SoldierSummon()
										wait(1)
										KommanderBossSummon()
										while true do
											wait(1)
											if workspace.Enemies:FindFirstChild("fighter") then
												
											else
												game.Workspace.musicfolder["K-ommander"]:Stop()
												CASHGIVE = 600
												GiveCash()
												script.Parent.Parent["NPC Icon"].Image = "http://www.roblox.com/asset/?id=15430831196"
												script.Parent.Parent.Parent.WAVEEND.Visible = true
												wait(3)
												script.Parent.Parent.Parent.WAVEEND.Visible = false
												script.Parent.Parent.Visible = true
												talk = "..."
												Talky2()
												wait(1)
												talk = "What did you just do to my apprentice?"
												Talky2()
												wait(1)
												script.Parent.Parent.Visible = false

												script.Parent.Parent.Parent.wavetext.Text = "wave 6"
												script.WAVE:Play()
												game.Workspace.musicfolder["wave 6 - 9"]:Play()


													DistractorSummon()
													wait(0.69)
												DistractorSummon()
													wait(0.69)
												DistractorSummon()
												for i = 1, 10, 0.5 do
													MinerSummon()
													wait(0.05)
												end
											
												wait(1)
												wait(2)
												wait(2)

												for i = 1, 5, 0.4 do
													SoldierSummon()
													wait(0.2)
													SoldierSummon()
													wait(0.2)
													SoldierSummon()
												end
												wait(2)
												wait(2)
												wait(2)

												for i = 1, 15, 0.5 do
													FighterSummon()
													wait(0.4)
													AssasinSummon()
													wait(0.4)
													SmasherSummon()
													wait(0.4)
												end
												
												DistractorSummon()
												wait(0.69)
												DistractorSummon()
												
												while true do
													wait(1)
													if workspace.Enemies:FindFirstChild("fighter") then
 
													else
														CASHGIVE = 500
														GiveCash()
														script.Parent.Parent.Parent.WAVEEND.Visible = true
														wait(3)
														script.Parent.Parent.Parent.WAVEEND.Visible = false
														script.Parent.Parent.Visible = true

														talk = "Yet i... I'll just get some snipers..."
														Talky2()
														wait(2.4)
														talk = "And some breserkers while im at it."
														Talky2()
														wait(2.3)
														talk = "Call in K-ommander's forces, we will need all the firepower."
														Talky2()
														wait(2.6)
														script.Parent.Parent.Visible = false

														script.Parent.Parent.Parent.wavetext.Text = "wave 7"
														script.WAVE:Play()
													end
												end
											end
										end
									end
								end
							end
						end
					end
				end
			end
		end
	end
end
---------------------

Goodluck if you want to attempt helping.

So is this a local script or script?

I’d guess from the code that this is a normal script since they are looping the Players to reward them money unless

It is in a normal script.

charss

The problem with that is that all scripts get “cloned” to the PlayerGui to each player and will all run simontaneously, put the Script somewhere else, like ServerScriptService

2 Likes

As coolyoshi said you should put this script into a server sided container like ServerScriptService rather than have it copied into every player’s PlayerGui.

I’m assuming your friend originally had it replicated to all players so that he could access the guis of each player through the script to change the text or whatever as the waves spawn. To keep this functionality you should create a RemoteEvent in ReplicatedStorage and have a local script in each player that handles all of the gui stuff in response to this main script calling FireAllClients.

For example,

Local script:


So in the local script you can make a table of functions to handle the different gui changes for the different stages of the game. Then you connect a function to the remote event that calls the function corresponding to whatever is specified by the server in the parameter part

Server script:


In the server script you would handle everything else like music and enemy spawning. At the beginning of each stage you would fire the event for all players so that their gui function activates while the server is doing this stuff.

Also as a side note your friend can clean up his code a lot by making use of function parameters. Instead of this for every single enemy,

function SoldierSummon()
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage.soldier:Clone()
	Fighter.Parent = workspace.Enemies
	if RANDOM1 == 1 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp1.CFrame
	end
	if RANDOM1 == 2 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp2.CFrame
	end
	if RANDOM1 == 3 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp3.CFrame
	end
	if RANDOM1 == 4 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp4.CFrame
	end
	if RANDOM1 == 5 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp5.CFrame
	end
	if RANDOM1 == 6 then
		Fighter.Torso.CFrame = game.Workspace.MAP.tp6.CFrame
	end
end

You can just make one function where you specify the enemy name:

function EnemySummon(enemyName)
	local RANDOM1 = math.random(1,6)
	local Fighter = game.ReplicatedStorage[enemyName]:Clone()
	Fighter.Torso.CFrame = workspace.MAP['tp'..tostring(RANDOM1)].CFrame
	Fighter.Parent = workspace.Enemies
end

This would cut down about half of the code lol