Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is causing my GameRounds script to break all of a sudden? (Capinbuilda)

Asked by 5 years ago

I was testing my GameRounds script for my game, and i wanted to ask do you know why it keep suddenly breaking?

What it does is, when you join your able to put about 3-5 short rounds into it then after that, it completely stop working, there is a team score keep and that suppose to show up but after the break it wont show, it suppose to teleport players to map but after break that stops, and the only way to fix is to rejoin the game which is a new server.

I tested it 3 times and all test the game broke at the map called hillside after the 5th so it could be anything but i do know this i really need a fix for this so could you please help me?

the script is over 400 lines long so this part of the code is were i think it is breaking.

function teleportPlayer(player)
    local shieldDuration = 5
    local character = player.Character
    local spawn = getRandomSpawn(player.TeamColor)
    local uppertorso = character.UpperTorso
    uppertorso.CFrame = spawn.CFrame + Vector3.new(0, 2, 0)
    local shield = Instance.new("ForceField", character)    
    game.Debris:AddItem(shield, shieldDuration)
    local backpack = player.Backpack
    local class = player.Class.Value
    local gun = game.Lighting.Guns.Tools[class]
    local gunHopperbin = gun.Gun:clone()
    gunHopperbin.Parent = backpack
    local playerScripts = game.Lighting.Scripts:GetChildren()
    for index, object in pairs(playerScripts) do
        object:clone().Parent = backpack
    end
end

function getRandomMode()
    local gameModes = {_G.eliminationRound, _G.teamSwapRound, _G.controllerRound,}
    local randomSlot = math.random(1, #gameModes)
    local randomMode = gameModes[randomSlot]
    roundType = gameModeNames[randomSlot]
    _G.announce("Round chosen: "..gameModeNames[randomSlot], Color3.new(0, 0, 0), 2)
    wait(1)
    local description = descriptions[randomSlot]
    for index, text in pairs(description) do
        _G.announce(text, Color3.new(0, 0, 0), 2)
        wait(1)
    end
    return randomMode
end

function getRandomMap()
    local gameMaps = game.Lighting.Maps:GetChildren()
    local randomMap = gameMaps[math.random(1, #gameMaps)]
    _G.announce("Map chosen: "..randomMap.Name, Color3.new(0, 0, 0), 2)
    return randomMap
end

function getRandomSpawn(teamColor)
    if (workspace:findFirstChild("Map")) then
        local spawns = {}
        if (teamColor == game.Teams.Red.TeamColor) then
            spawns = workspace.Map.Red:GetChildren()
        else
            spawns = workspace.Map.Blue:GetChildren()
        end
        local spawn = spawns[math.random(1, #spawns)]
        return spawn
    end
    return nil
end

function playerHasShirt(player, shirtID)
    local badgeService = game:GetService("BadgeService")
    if (badgeService:UserHasBadge(player.userId, shirtID)) then
        return true
    else
        return false
    end
end

function organizeTeams()
    local teamNum = 1
    repeat      
        local spectators = {}
        local teams = {"Red", "Blue"}
        local players = game.Players:GetChildren()
        for index, player in pairs(players) do
            if (player.TeamColor == game.Teams["Spectators"].TeamColor) then
                if (player.Character:findFirstChild("UpperTorso")) then
                    table.insert(spectators, player)
                end
            end
        end
        local randomPlayer = spectators[math.random(1, #spectators)]
        randomPlayer.TeamColor = game.Teams[teams[teamNum]].TeamColor
        teleportPlayer(randomPlayer)
        local spectatorNum = 0
        local players = game.Players:GetChildren()
        for index, player in pairs(players) do
            if (player.TeamColor == game.Teams["Spectators"].TeamColor) then
                if (player.Character:findFirstChild("UpperTorso")) then
                    spectatorNum = spectatorNum + 1
                end
            end
        end
        teamNum = (teamNum == 1) and 2 or 1
    until (spectatorNum == 0)
end

workspace.ChildAdded:connect(function(child)
    if (child.className == "Script") or (child.className == "LocalScript") then
        child:remove()
    end
end)

game.Players.ChildAdded:connect(playerEntered)

workspace.Showcase:remove()

while wait(1) do
    local numPlayers = game.Players.NumPlayers
    if (numPlayers >= minPlayers) then
        if (not gameStarted) then
            startGame()
        end
    else
        local difference = minPlayers - numPlayers
        local playerWord = (difference > 1) and "players" or "player"
        _G.announce("Waiting for "..difference.." more "..playerWord, Color3.new(0, 0, 0), 2)
    end
end

1
You shouldn't use _G or shared(). It is bad practice. You should start getting into the habit of using ModuleScripts saSlol2436 716 — 5y
1
By the way, you shouldn't wrap your conditionals in if statements with parenthesis. You should also not use :remove() and use :Destroy(). You should also use :Connect() instead of :connect() and use :Clone() instead of :clone() saSlol2436 716 — 5y
0
Ok thank you so much! This is some great information i will apply all these things to the script this should be a answer ill get upvote you to show my appriation. Carforlife1 59 — 5y

Answer this question