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

This script works in studio, but in-game it doesn't , why doesn't it put people on random teams?

Asked by 8 years ago

This is in a serverscript inside of serverscript service, I am showing whole script, but ill identify where the error is. Also, the output window doesn't print any errors, it just won't do anything, everything else runs smoothly. Could it be I did the teams with LocalPlayers in serverscripts?

local replicatedstorage = game:GetService('ReplicatedStorage')
local status = replicatedstorage:WaitForChild('InfoValue')
local mapstorage = game.Workspace:WaitForChild('mapStorage')
while true do
 --[[
 while game.Players.NumPlayers > 2 do
  status.Value = 'There needs to be more than one player to begin!'
  repeat wait(2) until game.Players.NumPlayers >= 2
end
]]
    for i = 15, 0, -1 do
        status.Value = 'Intermission '..i
        wait(1)
    end
    local mapsinserverstorage = game.ServerStorage.StorageMaps:GetChildren()
    local chosenmap = mapsinserverstorage[math.random(1, #mapsinserverstorage)]
    chosenmap:Clone().Parent = mapstorage

status.Value = "Map Spawned, prepare to fight soon!"
**
THIS AREA IS WHERE THE ERROR IS, IT WON'T PUT PEOPLE ON RANDOM TEAMS**
game.Players.LocalPlayer.Neutral = false
local newTeamBlue = game.ServerStorage.Blue:Clone()
local newTeamRed = game.ServerStorage.Red:Clone()
newTeamBlue.Parent = game.Teams
newTeamRed.Parent = game.Teams
    local teamValue = game.ServerScriptService.MainScript.TeamValue
    if teamValue.Value == 1 then
    game.Players.LocalPlayer.TeamColor = newTeamBlue.TeamColor
    teamValue.Value = 2
    else
    game.Players.LocalPlayer.TeamColor = newTeamRed.TeamColor
    teamValue.Value = 1
**ERROR IS UP HERE ^^^^^^**

wait(10)
    local spawns = chosenmap:WaitForChild('Spawns'):GetChildren()
    for _, player in pairs(game.Players:GetPlayers()) do
        if player and #spawns > 0 then
            local torso = player.Character:WaitForChild('Torso')
            local allspawns = math.random(1, #spawns)
            local randomspawn = spawns[allspawns]
            if randomspawn and torso then
                table.remove(spawns, allspawns)
                torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0, 2, 0))

                local sword = game.ReplicatedStorage.ClassicSword
                local newsword = sword:Clone()
                newsword.Parent = player.Backpack
            end
        end
    end
    for i = 180, 0, -1 do
        status.Value = i..' seconds left!'
        if i == 0 then
            status.Value = 'Times up!'
            for _, player in pairs(game.Players:GetPlayers()) do
                if player:FindFirstChild('leaderstats') then
                    player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 2
                end
            end
            break
        else
        end

        wait(1)
    end
    mapstorage:ClearAllChildren()

end
end


Answer this question