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

How do I teleport all players to a Part?

Everything runs but the sccript teleports me under the map while the part is above the map

function teleAll()
	local pos = Vector3.new(game.Workspace.FlightModel.PlayerHolder.Position)
	for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
		if plr.Character then
			plr.Character:MoveTo(pos)
		end
	end
end
teleAll()
print("done")

2 comments

0

MoveTo sometimes does weird things. Use CFrame

0

I'm not really good at Using CFrame

2 answers

✓ Accepted answer
function teleAll()
    local pos= game.Workspace.FlightModel.PlayerHolder.CFrame
    for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
        if plr.Character then
            plr.Character.HumanoidRootPart.CFrame = pos
        end
    end
end
teleAll()
print("done")

Basically, what we've changed here, is 2 things. first of all, the pos variable. The reason of this change inherits from the following change, so let's jump there. I'd recommend changing the CFrame of the humanoidrootpart more than using moveto because of various things:

  1. MoveTo, or changing torso's positions can cause death to the character
  2. There is no sort of 'collisions' when teleporting the characters, so the character will be teleported in that place correctly.
  3. I've changed the position of the part to the CFrame to the part so we could change the HRP's CFrame, although you can make a new cframe with the position. Tip: if you ever need the position of a CFrame you can use CFrame.P

hope this helped!

5 comments

0

It would give an error since CFrame isnt a member of Vector3

0

I've fixed it the edit came late

0

didnt actually see the vector3.new sorry, also that it would be unnecessary as position was already a vector3

0

Your edit is messed up, in line 5 its supposed to be plr.Character.HumanoidRootPart.CFrame = pos, not plr.Character.HumanoidRootPart.CFrame = CFrame

0

yeah my bad

Try CFrame. CFrame disables safe moving.

function TeleAll()
	local RequiredCFrame = workspace.FlightModel.PlayerHolder.CFrame
	for _, Player in pairs(game:GetService("Players"):GetPlayers()) do
		if Player.Character then
			plr.Character:WaitForChild("UpperTorso").CFrame = RequiredCFrame
		end
	end
end

TeleAll()
print("Done")

1 comment

0

changing the uppertorso will kill him i think

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