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

Players Teleporting to wrong plays?

I'm having a problem with the teleporting of my game. The problem is that the players spawn on the same place even though I "Table.Remove" the previous one. Here is the script:

if Status.Value == "Started" then
				for y, player in pairs(plrs) do
					
					local spawnPoints = game.Workspace.DanceStudioInside:FindFirstChild("SpawnDanceStudioDance")
					
					local AvailableSpawnPoints = spawnPoints:GetChildren()
					local char = player.Character or player.CharacterAdded:Wait()
					
					
					if player then
						if char then
							char:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame
							table.remove(AvailableSpawnPoints, 1)
						else
							if not player then
								table.remove(plrs, y)
							end
						end
						
				
						
						
					end
					
				end

1 answer

✓ Accepted answer

You're creating the 'AvailableSpawnPoints' table inside of a loop, meaning every iteration of the loop it just grabs every spawn point again. Make the table outside of the loop.

if Status.Value == "Started" then
                for y, player in pairs(plrs) do -- look here

                    local spawnPoints = game.Workspace.DanceStudioInside:FindFirstChild("SpawnDanceStudioDance")
		   - and here
                    local AvailableSpawnPoints = spawnPoints:GetChildren()
                    local char = player.Character or player.CharacterAdded:Wait()


                    if player then
                        if char then
                            char:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame
                            table.remove(AvailableSpawnPoints, 1)
                        else
                            if not player then
                                table.remove(plrs, y)
                            end
                        end




                    end

                end

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