Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.


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 == 1 then
	game.Players.LocalPlayer.TeamColor = newTeamBlue.TeamColor
	teamValue = 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

1 answer

I'm not sure if this is why it doesn't work, but on line 28, you're checking if teamValue (an Instance - possibly an IntValue) is equal to one. You should use teamValue.Value there.

1 comment

0

The same thing happened, worked in solo, but didn't work when I tested with multiple bots. Could it be I am using LocalPlayer in a serverscript?

This discussion is preserved as it was. New answers, comments, and votes are closed.