I am currently trying to start a single player zombie survival game, but I’m having an issue with the round system. Basically what’s supposed to happen is that each round begins and has a set amount of time in each round then after the round ends, if the player survives, the player receives one win and it goes into intermission. The problem is that the player doesn’t get any wins when completing a round and now the round system broke after I made the player’s character have to be manually spawned in.
Code:
--//variables
local RS = game:GetService("ReplicatedStorage")
local round = RS:WaitForChild("round").Value
local zombs = RS:WaitForChild("Dummies")
local event = RS:WaitForChild("roundEvent")
local deathMsg = RS:WaitForChild("deathMsg")
local startTime = 30
local players = game:GetService("Players")
local interlude = 20
local dumNum = RS:WaitForChild("dumNum").Value
local inRound = false
local match = true
local RF = game:GetService("ReplicatedFirst")
players.PlayerAdded:Connect(function(plr)
local gui = plr:WaitForChild("PlayerGui")
local UI = RF.MainUI:Clone()
UI.Parent = gui
--//spawning the player
RS.spawnPlr.OnServerEvent:Connect(function(plr)
plr:LoadCharacter()
end)
plr.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
local wins = plr.leaderstats:WaitForChild("Wins").Value
--//starting game
while hum.Health ~= 0 and match == true and plr:HasAppearanceLoaded() do
task.wait(interlude)
round += 1
event:FireAllClients(round)
--//spawns in zombies
for i = 0, dumNum-1, 1 do
local clone = zombs.Dummy:Clone()
clone.Parent = game.Workspace.Peds
local rand = math.random(1, 5)
if round >= 15 then
local tanky = zombs.Tanky:Clone()
if rand == 3 then
tanky.Parent = game.Workspace.Peds
clone:Destroy()
end
elseif round >= 5 then
local speedy = zombs.Speedy:Clone()
if rand == 1 then
speedy.Parent = game.Workspace.Peds
clone:Destroy()
end
end
end
--//makes player in round and increases amount of zombies for next round
inRound = true
dumNum += 5
--//checks if player has died since it has begun
if hum.Health == 0 then
match = false
inRound = false
break
end
if inRound == true then
--//checks again if player has died during round
if hum.Health == 0 then
match = false
inRound = false
break
end
task.wait(startTime)
--//increases amount of time per round and wins
startTime += 15
wins += 1
inRound = false
end
end
end)
end)
Thanks,
dza