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

Easy way to teleport players with eachother?

So I got a table with players in it, Is it possible to teleport everyone with eachother? So everyone changes position with a random player?

I tried to make a brick that saves the last position of the player and wanted to try to do smth with it but im not going far with it. Any Advice?

if i % 5 == 0 then
						-- Teleports every player with each other
						local posStone = Instance.new("Part")
						posStone.Transparency = 0
						posStone.Anchored = true
						posStone.CanCollide = false
						posStone.Parent = workspace.posStone
						posStone.CFrame = character:FindFirstChild("HumanoidRootPart").CFrame
					end

1 answer

✓ Accepted answer

Fantastic question. You had the right idea in saving their positions. This is the best way to do it.

charactersToMove = {} --List the characters instances, not their names
oldPos = {} --Dont touch
for _,v in pairs(charactersToMove) do
	table.insert(oldPos,v.HumanoidRootPart.CFrame)  --pack all possible cframes into a table
end
for i,v in pairs(characterToMove) do
	local numToSwitchTo
	repeat
		numToSwitchTo = math.random(1,#oldPos) --Choose a random position
	until
		numToSwitchTo and numToSwitchTo ~= i  --If this is their position or this position is already used, then choose another
	v:SetPrimaryPartCFrame(oldPos[numToSwitchTo]) --Move them to that position
	table.remove(oldPos,numToSwitchTo)  --Remove that position from the table to prevent it from being reused
end

This will switch any characters in characters to move position. I hope it helps. If there are any errors, just respond to my answer.

11 comments

0

Just do: table.insert(charactersToMove,workspace:FindFirstChild(--Put the character name here))

0

Question: How do I list the characters instances? I believe im not doing it right now, im inserting them with : for i, player in pairs(game.Players:GetPlayers()) do if player then table.insert(plrs, player) end end

0

Ah, just do this

0

for _,v in pairs(game.Players:GetPlayers()) do

0

table.insert(charactersToMove,v.Character)

0

end

0

I'll try, Thanks for all the help btw! You're getting an upvote as soon as it works xd

0

do you got discord? I dont know why im struggling so hard..

0

add me Janik #0737

0

k

0

Sent

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