Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
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?

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. climethestair 1663 — 5y
0
What do you mean by, "sometimes players are not teleported as they should be"? SummerEquinox 643 — 5y
0
use the HumanoidRootPart; it's better and is foolproof DeceptiveCaster 3761 — 5y
0
You can use distance or Region3 to detect players near the part hellmatic 1523 — 5y
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. mantorok4866 201 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

0
ok, I will use this method, thank you for your help. mantorok4866 201 — 5y
Ad
Log in to vote
0
Answered by
WXBZ 3
5 years ago
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)

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. mantorok4866 201 — 5y
Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
5 years ago

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

0
Teleporting, not walking... greatneil80 2647 — 5y
0
im curious, is there a difference between using cframe to move a character and moving the entire player with moveto? mantorok4866 201 — 5y

Answer this question