His script doesnt work I think I put it into the wrong place. How long will it take until your script is done?
About 3 mins im right now checking if player has died then remove tag. Might take longer tho.
Yeah ok thankyou I gtg soon so I will use your code later today.
local Waves = game.ServerStorage.Waves
local event = game.ReplicatedStorage.Event
local currentwave = 1
for i,v in pairs(Waves:GetChildren()) do
if script.Parent.Wave ~= currentwave then
currentwave = script.Parent.Wave
if game.Workspace["Wave"..currentwave].Monsters.Value == 0 then
end
end
end
local event = game.ReplicatedStorage.Event
local Waves = game.ServerStorage.Waves
local Players = game.Players:GetChildren()
local function onEvent()
startwave()
end
function startwave()
local Wave = Waves["Wave"..currentwave]:Clone()
Wave.Parent = game.workspace
for i,v in pairs(game.Players:GetChildren()) do
local alive = Instance.new("BoolValue",v)
alive.Name = "Alive"
alive.Value = false -- Doesn't matter.
end
repeat
wait(0.5)
until game.Workspace["Wave"..currentwave].Monsters.Value == 0
for i,v in pairs(game.Players:GetChildren()) do
if v:FindFirstChild("Alive") then
v:FindFirstChild("leaderstats").Coins.Value = v:FindFirstChild("leaderstats").Coins.Value + 10
end
end
onEvent()
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
wait(.1)
character.Humanoid.Died:Connect(function()
if player:FindFirstChild("Alive") then
player:FindFirstChild("Alive"):Destroy()
end
end)
end)
end)
event.Event:Connect(onEvent)
I donāt really know if this will work so tell me if it does.
Ok do I have to make any modifications to my zombies etc or not?
I get this error in the output:
Wave1 is not a valid member of workspace
Actually I have Fixed the porlblem!
Im testing if it works now
Sorry your code doesnt work when the round ends it starts spawning zombies at rapid rate and then when the new map comes there are lots of zombies causing insane lag. Can you modify the script to fix it?
Thats not really what you asked for⦠I used your code so either way your code wouldāve done the sameā¦
Oh? Really I dont think so but ok.
Are you sure you wrote this script? Because if you did than you should be able to figure out stuff like this easily.
Make sure to create a bindable event and name it WaveFinish
.
RoundScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MapsFolder = ServerStorage:WaitForChild("Maps")
local Status = ReplicatedStorage:WaitForChild("Status")
local GameLength = 360
--local reward = 1
--local cash = math.random(1200,3000)
local StartGame = game.ReplicatedStorage.Event
local WaveFinishEvent = game.ReplicatedStorage.WaveFinish -- create a bindable event called WaveFinish
local plrs = {}
-- Award Players
function AwardPlayers(Amount)
if Amount == nil then warn("Amount cannot be nil") end
for _,plr in pairs(plrs) do -- plrs is global a table
plr:FindFirstChild('leaderstats').Coin.Value = plr:FindFirstChild('leaderstats').Coin.Value + Amount
end
end
WaveFinish.Event:Connect(function(waveNumer) -- Award when wave is finshed
if #plrs >= 1 then
AwardPlayers(10)
print("End of the wave",i)
end
end)
-- Game loop
while true do
Status.Value = "Waiting for enough players to start"
repeat wait() until game.Players.NumPlayers >= 2
Status.Value = "Intermission"
wait(20)
plrs = {}
for i, player in pairs(game.Players:GetPlayers()) do
if player then
table.insert(plrs,player) -- Add each player into plrs table
end
end
local AvailableMaps = MapsFolder:GetChildren()
local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]
Status.Value = ChosenMap.Name.." is the chosen Map"
local ClonedMap = ChosenMap:Clone()
ClonedMap.Parent = workspace
-- Teleport players to the map
Status.Value = "Preparing Arena"
wait (5)
local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
if SpawnPoints == nil then
print("Spawnpoints not found!")
end
local AvailableSpawnPoints = SpawnPoints:GetChildren()
for i, player in pairs(plrs) do
if player then
character = player.Character
if character then
-- Teleport them
character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[i].CFrame + Vector3.new(0,10,0)
table.remove(AvailableSpawnPoints,i)
-- Give them a sword and a revolver
local equipped = game.ServerStorage.PlayerData[player.Name].Equipped
if equipped.Value ~= "" then
local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
weapon.Parent = player.Backpack
else
local Knife = ServerStorage.Pistol:Clone()
Knife.Parent = player:WaitForChild("Backpack")
end
local GameTag = Instance.new("BoolValue")
GameTag.Name = "GameTag"
GameTag.Parent = player.Character
else
-- There is no character
if not player then
table.remove(plrs,i)
end
end
end
end
StartGame:Fire()
print ("EventFired")
for i = GameLength,0,-1 do
for x, player in pairs(plrs) do
if player then
character = player.Character
if character == nil then
-- Left the game
table.remove(plrs,x)
else
if character:FindFirstChild("GameTag") ~= nil then
-- They are still alive
print(player.Name.." is still in the game!")
else
-- They are dead
table.remove(plrs,x)
print(player.Name.." has been removed!")
end
end
else
table.remove(plrs,x)
print(player.Name.." has been removed!")
end
end
Status.Value = "There are "..i.." seconds remaining, and "..#plrs.." players left"
if #plrs == 0 then
Status.Value = "Monsters have defeated you!"
end
wait(1)
end
print("End of game")
wait(2)
for i, player in pairs(game.Players:GetPlayers()) do
character = player.Character
if character ~= nil then
--[[if character:FindFirstChild("GameTag") then
character.GameTag:Destroy()
end
for _, tool in pairs(player.Backpack:GetChildren()) do
if tool:FindFirstChild("Price") then
tool:Destroy()
end
end
for _, tool in pairs(character:GetChildren()) do
if tool:FindFirstChild("Price") then
tool:Destroy()
end
end --]]
player:LoadCharacter() -- Once you load character everything inside the character and Backpack gets removed
end
end
ClonedMap:Destroy()
Status.Value = "Game ended"
wait(2)
end
WaveScript
local StartGame = game.ReplicatedStorage.Event
local WaveFinishEvent = game.ReplicatedStorage.WaveFinish -- create a bindable event called WaveFinish
local Waves = game.ServerStorage.Waves
local function WaveHandle()
wait (0.5)
for i=1,#Waves:GetChildren() do
local currentWave = Waves:FindFirstChild("Wave"..i)
if currentWave ~= nil then
local waveCopy = currentWave:Clone()
waveCopy.Parent = workspace
repeat
wait(0.5)
until waveCopy.Monsters.Value == 0
end
waveCopy:Destroy()
WaveFinishEvent:Fire(i)
end
end
StartGame.Event:Connect(WaveHandle)
I wrote the wave script by myself.
I have made a few modifications to your script to make it work correctly. Im testing it right now.
Thankyou so much your scripts work with some modification!