Hey devs!
Sorry if I seem dumb here, I’m very tired and just got out from a tornado warning, kind of frightened and delirious right now, but:
I had a round script that worked 100% fine yesterday and most of today until this past 2 hours. It suddenly broke in the round loop and ignored all of the round code and jumps right back to the intermission after loading the map.
I’ve tried moving code around, changing code entirely, but ended up reverting it back to the old code. I can’t seem to fix it.
It is inside of a module script that has a server script run everything important for the game and leaderstats (leaderstats aren’t important for this).
Entire Server Code:
--Change CFrame value for tools: game.StarterGui.MainGui.Frames.Shop.Frames.Items.Purchase.ItemViewport.Blank.CameraCFrame.Value = game.Workspace.CurrentCamera.CFrame
local Players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local serverStorage = game:GetService("ServerStorage")
local marketPlaceService = game:GetService("MarketplaceService")
local mainGame = replicatedStorage:WaitForChild("MainGame")
local remotes = mainGame:WaitForChild("Remotes")
local gameValues = mainGame:WaitForChild("GameValues")
local status = gameValues:WaitForChild("Status")
local round = require(script.Round)
local leaderstats = require(script.Leaderstats)
local bindableEvent = Instance.new("BindableEvent")
bindableEvent.Name = "BindableEvent"
bindableEvent.Parent = remotes
local minimumPlayers = 2
local intermissionTime = 20
local gameLength = 180
local vipGamePass = 42960558
local extraSpeedGamePass = 43113220
local playersLeft = 0
for _, object in pairs(workspace.Camera:GetChildren()) do
object:Destroy()
end
Players.PlayerAdded:Connect(function(player)
leaderstats.LoadChatTags(player)
leaderstats.LoadLeaderstats(player)
playersLeft = playersLeft + 1
end)
Players.PlayerRemoving:Connect(function(player)
leaderstats.SaveData(player)
playersLeft = playersLeft - 1
end)
while true do
round.Waiting(Players.NumPlayers)
repeat task.wait(1) until Players.NumPlayers >= minimumPlayers
round.Intermission(intermissionTime)
round.StartRound(gameLength)
task.wait(3)
end
game:BindToClose(function()
while playersLeft > 0 do
bindableEvent.Event:Wait()
end
end)
Entire Module Code:
local Players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local lighting = game:GetService("Lighting")
local tweenService = game:GetService("TweenService")
local serverStorage = game:GetService("ServerStorage")
local marketPlaceService = game:GetService("MarketplaceService")
local maps = serverStorage:WaitForChild("MainGame"):WaitForChild("Maps")
local mainGame = replicatedStorage:WaitForChild("MainGame")
local remotes = mainGame:WaitForChild("Remotes")
local gameValues = mainGame:WaitForChild("GameValues")
local status = gameValues:WaitForChild("Status")
local vipGamePass = 42960558
local tripleExpPass = 43694425
local cashReward = 75
local expReward = 75
local function toMS(s)
return ("%02i:%02i"):format(s/60%60, s%60)
end
local round = {}
function round.Waiting(numberOfPlayers)
gameValues:WaitForChild("Status").Value = "2 Ready players are required to start ("..numberOfPlayers.."/2 Players)"
end
function round.Intermission(intermissionTime)
for i=intermissionTime,0,-1 do
status.Value = "Intermission ("..i..")"
task.wait(1)
end
end
function round.StartRound(gameLength)
status.Value = ""
local plrs = {}
for i, player in pairs(Players:GetPlayers()) do
if player then
table.insert(plrs,player)
end
end
task.wait(2)
local availableMaps = maps:GetChildren()
local chosenMap = availableMaps[math.random(1,#availableMaps)]
status.Value = chosenMap.Name.." was selected"
task.wait(2)
local newMap = chosenMap:Clone()
newMap.Name = chosenMap.Name
newMap.Parent = workspace
local spawnPoints = newMap:FindFirstChild("SpawnPoints")
if not spawnPoints then
warn("Critical Error: There are no spawn points in "..chosenMap.Name.."!")
end
local availableSpawns = spawnPoints:GetChildren()
for i=5,0,-1 do
status.Value = "Game will start in "..i
task.wait()
end
newMap.Music:Play()
for i, plr in pairs(plrs) do
if plr then
local character = plr.Character or plr.CharacterAdded:Wait()
if character then
task.wait(1.2)
character.Humanoid.Sit = false
character.HumanoidRootPart.Position = availableSpawns[1].Position + Vector3.new(0, 8, 0)
table.remove(availableSpawns,1)
local hitbox = serverStorage.MainGame.Templates.Hitbox:Clone()
hitbox.Parent = plr.Character
hitbox.CFrame = plr.Character.HumanoidRootPart.CFrame
local weld = Instance.new("Weld")
weld.Parent = hitbox
weld.Part0 = hitbox
weld.Part1 = plr.Character.HumanoidRootPart
local swordClone = serverStorage.MainGame.Tools.ClassicSword:Clone()
swordClone.Parent = plr.Backpack
local equipped = serverStorage.MainGame.PlayerData[plr.Name].Equipped
if equipped.Value ~= "" then
local weapon = serverStorage.MainGame.Tools.ShopTools[equipped.Value]:Clone()
weapon.Parent = plr.Backpack
else
return
end
local gameTag = Instance.new("BoolValue")
gameTag.Name = "GameTag"
gameTag.Parent = plr.Character
end
else
if not plr then
table.remove(plrs,i)
end
end
end
for i=gameLength,0,-1 do
for x, player in pairs(plrs) do
if player then
local character = player.Character
if not character then
table.remove(plrs,x)
else
if character:FindFirstChild("GameTag") then
--Still in game
else
table.remove(plrs,x)
player.leaderstats.Cash.Value += 5
plrs[1].leaderstats.Level.CurrentExp.Value += 10
end
end
else
table.remove(plrs,x)
end
end
status.Value = "Time: "..toMS(i).." remaining"
if #plrs == 1 then
status.Value = "Cleaning Up: The winner is "..plrs[1].Name..". Congrats!"
if marketPlaceService:UserOwnsGamePassAsync(plrs[1].UserId, vipGamePass) then
plrs[1].leaderstats.Cash.Value += (cashReward * 0.2 + cashReward)
plrs[1].leaderstats.Level.CurrentExp.Value += (expReward * 0.2 + expReward)
elseif marketPlaceService:UserOwnsGamePassAsync(plrs[1].UserId, tripleExpPass) then
plrs[1].leaderstats.Cash.Value += cashReward
plrs[1].leaderstats.Level.CurrentExp.Value += (expReward * 3)
elseif marketPlaceService:UserOwnsGamePassAsync(plrs[1].UserId, vipGamePass) and marketPlaceService:UserOwnsGamePassAsync(plrs[1].UserId, tripleExpPass) then
plrs[1].leaderstats.Cash.Value += (cashReward * 0.2 + cashReward)
plrs[1].leaderstats.Level.CurrentExp.Value += (expReward * 0.2 + expReward * 3)
else
plrs[1].leaderstats.Cash.Value += cashReward
plrs[1].leaderstats.Level.CurrentExp.Value += expReward
end
break
elseif #plrs == 0 then
status.Value = "Restarting: No one has won the game."
break
elseif i == 0 then
status.Value = "Restarting: Time has run out."
break
end
task.wait(1)
end
task.wait(1.5)
for i, player in pairs(Players:GetPlayers()) do
local character = player.Character
if not character then
--Ignore this player
else
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
end
player:LoadCharacter()
end
status.Value = "Cleaning up last round"
task.wait(3)
newMap:Destroy()
task.wait(7)
end
return round
Sorry if the code is a lot to read!
I can be a real doofus sometimes, so any help is appreciated! Thanks!
I genuinely don’t know what broke, before there was a tornado it was fine, afterwards code broke out of no where.
Best regards,
RoboBoy013