Good morning yall. I have been working on a game and it has been going well, until during the play tests when someone joins mid-round. The issues caused when someone joins mid round is that the round systems stop and like the while loop doesn’t do anything. Another thing that doesn’t work is my lifetime wins tracker gui and it doesn’t update when the player joins the game.
Core Gameplay Script:
local firstLayer = workspace.firstLayer
local playersLeft = 0
local colorInGame = false
local colors = {BrickColor.new("Alder"), BrickColor.new("Baby blue"), BrickColor.new("Beige"), BrickColor.new("Bright blue"), BrickColor.new("Bright bluish green"), BrickColor.new("Burgundy"), BrickColor.new("Med. reddish violet"), BrickColor.new("Camo"), BrickColor.new("Cadet blue"), BrickColor.new("Bright orange"), BrickColor.new("Buttermilk"), BrickColor.new("Cashmere"), BrickColor.new("Daisy orange"), BrickColor.new("Carnation pink"), BrickColor.new("Lavender"), BrickColor.new("Mint"), BrickColor.new("Light blue"), BrickColor.new("Laurel green"), BrickColor.new("Tawny"), BrickColor.new("Seashell")}
while true do
for i = 15, 0, -1 do
game.ReplicatedStorage.statusText.Value = "INTERMISSION: " .. i
wait(1)
end
game.ReplicatedStorage.statusText.Value = "GAME ON-GOING"
for _, v in pairs(game.Players:GetPlayers()) do
v.Character.HumanoidRootPart.CFrame = CFrame.new(math.random( 1, 41), 150, math.random( -213.5, -178))
v.varibles.inRound.Value = true
end
repeat
playersLeft = 0
for _, v in pairs(firstLayer:GetChildren()) do
local color = colors[math.random(1, #colors)]
v.BrickColor = color
end
for _, v in pairs(workspace.secondLayer:GetChildren()) do
local color = colors[math.random(1, #colors)]
v.BrickColor = color
end
for _, v in pairs(workspace.thirdLayer:GetChildren()) do
local color = colors[math.random(1, #colors)]
v.BrickColor = color
end
local chosenColor = colors[math.random(1, #colors)]
game.ReplicatedStorage.colorTeller:FireAllClients(chosenColor)
wait(5)
for _, v in pairs(firstLayer:GetChildren()) do
if v.BrickColor ~= chosenColor then
v.Transparency = 1
v.CanCollide = false
end
end
for _, v in pairs(workspace.secondLayer:GetChildren()) do
if v.BrickColor ~= chosenColor then
v.Transparency = 1
v.CanCollide = false
end
end
for _, v in pairs(workspace.thirdLayer:GetChildren()) do
if v.BrickColor ~= chosenColor then
v.Transparency = 1
v.CanCollide = false
end
end
for i, v in pairs(workspace.levelBarriers:GetChildren()) do
v.CanCollide = true
end
wait(5)
for i, v in pairs(workspace.levelBarriers:GetChildren()) do
v.CanCollide = false
end
for _, v in pairs(firstLayer:GetChildren()) do
v.Transparency = 0
v.CanCollide = true
end
for _, v in pairs(workspace.secondLayer:GetChildren()) do
v.Transparency = 0
v.CanCollide = true
end
for _, v in pairs(workspace.thirdLayer:GetChildren()) do
v.Transparency = 0
v.CanCollide = true
end
for _, v in pairs(game.Players:GetPlayers()) do
if v.varibles.inRound.Value == true then
playersLeft = playersLeft + 1
print(playersLeft)
end
end
until playersLeft <= 1
playersLeft = 0
for _, v in pairs(game.Players:GetPlayers()) do
if v.varibles.inRound.Value == true then
v.varibles.wins.Value = v.varibles.wins.Value + 1
end
local spawnPoint = workspace.Spawns:GetChildren()[math.random(1,#workspace.Spawns:GetChildren())]
v.Character.HumanoidRootPart.CFrame = spawnPoint.CFrame + Vector3.new(0, 5, 0)
v.varibles.inRound.Value = false
end
end
Data Store Script:
local dataStoreService = game:GetService("DataStoreService")
local winsStorage = dataStoreService:GetDataStore("winsStorage01")
game.Players.PlayerAdded:Connect(function(player)
local varibles = Instance.new("Folder")
varibles.Parent = player
varibles.Name = "varibles"
local inRound = Instance.new("BoolValue")
inRound.Parent = player.varibles
inRound.Value = false
inRound.Name = "inRound"
local wins = Instance.new("IntValue")
wins.Parent = varibles
wins.Value = 0
wins.Name = "wins"
local success, numWins = pcall(function()
return winsStorage:GetAsync(player.UserId.."E")
end)
if success then
print("Data Loaded")
player.varibles.wins.Value = numWins
print(player.varibles.wins.Value)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, err = pcall(function()
winsStorage:SetAsync(player.UserId.."E", player.varibles.wins.Value)
print(player.varibles.wins.Value)
end)
if success then
print("Success!")
end
end)