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

Why isn't this script working, it brings players to spawn points?

It's supposed to bring players to spawns. (1 player per spawn)

function BringPlayers()
	function BringPlayers()
    local Spawns = game.Workspace.Map.MapSpawners:GetChildren()
    local Players = game.Players:GetPlayers()
    for i = 1, #Players do
        local SelectedSpawn = table.remove(Spawns,math.random(#Spawns))
        local Spawn = Spawns[SelectedSpawn]
        if Players[i].Character then --Make sure they are spawned in
            local Torso = Players[i].Character.UpperTorso
           Torso.CFrame = Spawn.Spawn.CFrame
        end
    end
	end
	end

1 comment

0

also, there is no errors in output.

1 answer

✓ Accepted answer
function BringPlayers()
   	local Spawns = game.Workspace.Map.MapSpawners:GetChildren()
    	local Players = game.Players:GetPlayers()
  		for i = 1, #Players do
       		local SelectedSpawn = math.random(#Spawns)
       		local Spawn = Spawns[SelectedSpawn]
        	if Players[i].Character then --Make sure they are spawned in
           		Players[i].Character:SetPrimaryPartCFrame(Spawn.Spawn.CFrame)
			table.remove(Spawns,SelectedSpawn)
       		end
 	end
end

Don't set a variable to table.remove as that will never work right as you just removed the value you want. I also changed setting the torso CFrame(Your code would only work for R15) and using SetPrimaryPartCFrame on a model is generally better.

I also removed the 2and BringPlayers() as this prevents executing the code at all

the remove code is also inside the if statement now so that if there is no character to move, the spawn can still be used for a different player.

Hope this helped

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