Problem: Let met get this straight. It does work HOWEVER there are some occasions that it will still spawn a player back in the room when they spawn into the game. Here is how the game is set up spawn wise. When a player joins they are automatically put into lets call it "New Players" then they can choose between four other teams that they can change to by walking over a brick. Now this script is suppose to make it that this player can only spawn in the spawns designated to that team, no where else. The thing is every so often they will spawn back to spawn, but if they reset they can go back to the teams spawn. I think it might be because I am not turning the "AutoAssignable" off on the "New Players" team. Thing is when I did that and tested the theory it still did it. Another theory is that an error arises in this script I am about to put. It might be what is hindering the script sometimes to not function correctly. Note: The code in the tables is reference to the team spawnlocations....
script :
local spawnbox = game.Workspace.SpawnBoxSpawns
local sly = game.Workspace.SlySpawns
local gryff = game.Workspace.GryffSpawns
local raven = game.Workspace.RavenSpawns
local huff = game.Workspace.HuffSpawns
local spawn1 = {sly:GetChildren()}
local spawn2 = {gryff:GetChildren()}
local spawn3 = {raven:GetChildren()}
local spawn4 = {huff:GetChildren()}
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
if plr.TeamColor.Name == "Medium stone grey" then
print("NewStudents")
char.Torso.CFrame = math.random(1, spawnbox:GetChildren()).CFrame + Vector3.new(0,4,0)
print("Spawn here")
elseif
plr.TeamColor.Name == "Bright red" then
print("Gryffindor")
char.Torso.CFrame = math.random(1, #spawn2).CFrame + Vector3.new(0,4,0)
print("Spawn here")
elseif
plr.TeamColor.Name == "Bright yellow" then
print("Hufflepuff")
char.Torso.CFrame = math.random(1, #spawn4).CFrame + Vector3.new(0,4,0)
print("Spawn here")
elseif
plr.TeamColor.Name == "Bright blue" then
print("Ravenclaw")
char.Torso.CFrame = math.random(1, #spawn3).CFrame + Vector3.new(0,4,0)
print("Spawn here")
elseif
plr.TeamColor.Name == "Bright green" then
print("Slytherin")
char.Torso.CFrame = math.random(1, #spawn1).CFrame + Vector3.new(0,4,0)
print("Spawn here")
else
return nil
end
end)
end)
P.S. The error reads 12:36:39.052 - Workspace.Teamsorter stuff:42: attempt to index a number value But it will also say the same for the other lines that involve putting the torso to that spawn locations with the teams. I just so happened to be on that particular team when it errored too. Also, frankly, I am out of ideas on how to fix my script. It could also be I am misusing the indexing in a way. But I don't know.
