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

is there a better way to move a player to another location?

local core = game.Workspace.ExpansePortalStart
script.Parent.Touched:connect(function(hit) 
 if hit.Parent:FindFirstChild('Humanoid') then 
  hit.Parent.Head.CFrame = CFrame.new(core.Position)
 end
end)

so I have a script that moves players in a specified area to another location, but the problem is sometimes players are not teleported as they should be, Is there a more efficient way of teleporting players?

5 comments

0

CFrame, MoveTo (humanoid), MoveTo (Model), SetPrimaryPartCFrame, your way is most likely the most efficient besides not having a debounce in your touch function to limit the number of times it tries to change the CFrame when touched.

0

What do you mean by, "sometimes players are not teleported as they should be"?

0

use the HumanoidRootPart; it's better and is foolproof

0

You can use distance or Region3 to detect players near the part

0

summerequinox when a group of players enters an area, all of them are on the brick, after a certain amount of time the script is enabled and all payers standing on the brick are teleported, but sometimes one or more players do not teleport, that my main issue.

3 answers

✓ Accepted answer

Teleporting, eh? Your best bet for doing so is CFrame. (The MoveTo() method makes your character walk to the given location, so ignore any answers involving MoveTo().) Your script:

local core = game.Workspace.ExpansePortalStart
script.Parent.Touched:connect(function(hit) 
 if hit.Parent:FindFirstChild('Humanoid') then 
  hit.Parent.Head.CFrame = CFrame.new(core.Position)
 end
end)

Two things I noticed here were that you were using the Character's Head to teleport and that you were using the undercase version of Connect(), which is basically useless at this point. For teleporting, it is recommended that you use the HumanoidRootPart's CFrame and not the Head's CFrame, As the name might give away, the HumanoidRootPart is your Character's only Part that is linked directly to the Humanoid, which means that teleportation would become a whole lot easier. (The HumanoidRootPart is also the Part you would use to script animations.) Scripting Helpers also recommends using Connect(), the successor to connect(). This is because the way you write code in Roblox involves more capitalization now than it did 6 years ago. These are just a few recommendations to follow, after all.

Here are other ways to teleport in Roblox (MoveTo() is not a teleportation method for obvious reasons):

  • Teleporting to different places (TeleportService)

  • CFrame teleporting by receiving a command in chat (ChatService)

That's all I know, and I hope you will heed attention on how to efficiently teleport Roblox players.

1 comment

0

ok, I will use this method, thank you for your help.

Hello, mantorok4866!

You should try to use MoveTo.

local core = game.Workspace.ExpansePortalStart
script.Parent.Touched:connect(function(hit) 
 if hit.Parent:FindFirstChild('Humanoid') then 
  hit.Parent:MoveTo(core.Position) --Use the "MoveTo" function to move the full character model
 end
end)

Good Luck with your games

2 comments

0

Teleporting, not walking...

0

im curious, is there a difference between using cframe to move a character and moving the entire player with moveto?

local core = game.Workspace.ExpansePortalStart
script.Parent.Touched:connect(function(hit) 
 if hit.Parent and game:GetService("Players"):FindFirstChild(hit.Parent.Name) then 
  hit.Parent:SetPrimaryPartCFrame(core.CFrame)
 end
end)

1 comment

0

leamir remade the script in the same way, Im putting the script in a brick that when enabled players that touch the brick are teleported, the issue is either the script fails to work if the player does not move or the script fails to run from server lag, I just wanted to know if there was a better way of handling a group of players with minimal delay.

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