Basically, I have this script that creates pedestals according to the number of players in the game, and when a certain number of players are in the game, I want the script to teleport all the players onto a different pedestal.
UPDATE: I have written a script with the help of Royaltoe, but when the player teleports to the pedestal, they are clipped inside of it then pop out, I just want them to be standing immediately. I tried editing the position of the CFrame, but i am not having any luck. Any help is greatly appreciated!
--getting the "Players" service local Players = game:GetService("Players") local function teleportPlayer(character, index) wait(0.5) local numPlayers = #game.Players:GetPlayers() local pedestal = workspace:FindFirstChild("CompletedPedestal_"..index) local HumanoidRootPart = character.HumanoidRootPart HumanoidRootPart.CFrame = pedestal.PedestalBase.CFrame * CFrame.new(Vector3.new(0, 0 , 0)) end local function onPlayerAdded(player) local players = game.Players:GetChildren() local minPlayers = 4 --check if we have enough players if #players >= minPlayers then wait(6) --loop thru the players in the players table for index, player in pairs(players) do --if the player's character exists if player.Character then --teleport the player to their pedestal teleportPlayer(player.Character, index) end end end local numPlayers = #game.Players:GetPlayers() end local function onPlayerRemoved() local numPlayers = #game.Players:GetPlayers() end game.Players.PlayerAdded:Connect(onPlayerAdded) game.Players.PlayerRemoving:Connect(onPlayerRemoved)
We figured out how to make it in discord so some information might be left out but tried to explain as much as I could.
If you're reading this and have similar problem, let me know and we can probably figure it out.
Here is how we created the pedestals: We're cloning a model from the serverstorage (the pedestal) every time a player joins the game and removing one every time the player leaves the game.
--function to create pedestal. the pedestal number is based on how many players are currently in game local function createPedestal(position, partNum) local Pedestal = game.ServerStorage.CompletedPedestal local Clone = Pedestal:Clone() Clone.Parent = workspace wait(0.5) Clone.Name = "CompletedPedestal_"..partNum Clone:MoveTo(position) return Clone end --remove pedestal when player leaves game local function destroyPedestal(num) workspace:FindFirstChild("CompletedPedestal_"..num):Destroy() end --function that runs when the player joins the game local function onPlayerAdded() local num = #game:GetService("Players"):GetPlayers() wait(0.5) --figure out where to move the pedestal local pos = game.ServerStorage.CompletedPedestal.PedestalBase.Position - Vector3.new(0,0,(10*num)) --create pedestal createPedestal(pos, num) end local function onPlayerRemoved() local num = #game:GetService("Players"):GetPlayers()+1 destroyPedestal(num) end game.Players.PlayerAdded:Connect(onPlayerAdded) game.Players.PlayerRemoving:Connect(onPlayerRemoved)
We teleported the player by changing the player's humanoidrootpart's cframe. and setting it equal to a part named teleport part inside of each pedestal model.
local Players = game:GetService("Players") --getting the "Players" service --teleports a player to a pedestal local function teleportPlayer(character, index) wait(0.5) --find pedestal to teleport to local pedestal = workspace:FindFirstChild("CompletedPedestal_"..index) --teleport to pedestal character.HumanoidRootPart.CFrame = pedestal.TeleportPart.CFrame end --code that runs when a player joins local function onPlayerAdded(player) local players = game.Players:GetChildren() --get a list of all the players in game local minPlayers = 4 --the minimum number of players we need to start the game --check if we have enough players if #players >= minPlayers then wait(6) --if we have enough players, loop thru the players in the players table for index, player in pairs(players)do if player.Character then --make sure the player's character exists teleportPlayer(player.Character, index) --teleport character to pedestal end end end end game.Players.PlayerAdded:Connect(onPlayerAdded)
I would recommend making a folder in Workspace called "pedestals", where you store all the pedestals. Then after you have the certain amount of players needed, you just simply loop through the Players and use the MoveTo()
function to move them to the corresponding pedestal.
Here's an example;
function MovePlayers() local pedestals = game.Workspace.pedestals:GetChildren()--Makes a table for i,v in pairs(game.Players:GetChildren())do --Loops through table of Players v:MoveTo(pedestals[i].Position) end end