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

How would I go about teleporting multiple characters to a bunch of pedestals?

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)

2 comments

0

When do you want to teleport the player to the pedestal? On start? Use game.Players.PlayerAdded

0

no, i want it to teleport a bunch of players to their own pedestal when there is a certain amount of players in the game. I already know how to handle the amount of players in the game, I just don't know how to actually teleport the characters.

2 answers

✓ Accepted answer

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

6 comments

0

OMG, I am so sorry, i also forgot to mention that i have a script which is creating a row of pedestals for me depending on the number of players in the game

0

Yup, this should work perfectly fine then. Call this function after the number of Players check

0

my pedestal is inside of the ServerStorage, and then i clone it to the workspace

0

I don't see what the problem is here... just parent the cloned pedestals to the folder in Workspace.

0

have you looked at the new code i have provided?

0

Yeah, use MoveTo. CFrame clips, but using Vector3 accounts for that.

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