I'm trying to teleport players to a certain block when there are a certain number of players in the game (I put 0 just to test it out). The teleport works if I put in actual coordinates, but once I fill it with the variable it doesn't.
playernumber = #game.Players:GetChildren() islandposition = game.Workspace.Islands.Island1.Position.Unit target = CFrame.new(islandposition) if playernumber>0 then for i, player in ipairs(game.Players:GetChildren()) do if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0) end end end
local Players = game:GetService("Players") -- We get [game.Players]; local Target = game.Workspace.Part -- Define the instance to where we wish to teleport the players. local RequiredPlayers = 0; Players.PlayerAdded:connect(function() -- We run our function everytime a player is added. if(#Players:GetPlayers() > RequiredPlayers) then -- We check if the total amount of players in the game is over the required amount of players. for _,Player in ipairs(Players:GetPlayers()) do -- GetPlayers() gives us a table that contains all the players in the game, similar to :GetChildren(). if Player.Character and Player.Character:WaitForChild("HumanoidRootPart") then -- Check if Player.Character and .. exists. Player.Character.HumanoidRootPart.CFrame = Target.CFrame + Vector3.new(0, _ * 5, 0) --Your issue was that you weren't defining the target coordinates properly -- In your script, target = CFrame.new(islandposition) should be replacted with Target = islandposition.CFrame; end end end end)
I think that code should just about work, if it doesn't just tell me ^-^. Feel free to ask any questions.