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?
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.
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)
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