Teleporting player disrupts movement

I am making an auto run feature for my game and in order for it to work I teleport the player to the middle of the map.

However, after teleporting for some reason player movement starts acting very weird and a bit unresponsive as you can see in this video

Here are the scripts which do the teleporting:
(client)

inRace.Changed:Connect(function()
	if inRace.Value == true then
		if autoRun.Value == true then
			teleport:FireServer(player)
		end
	end
end)

(server)

local replicatedStorage = game:GetService("ReplicatedStorage")
local events = replicatedStorage:WaitForChild("events")
local teleport = events:WaitForChild("teleportPlayer")

teleport.OnServerEvent:Connect(function(player)
	local character = player.Character
	if not character or not character.Parent then
		character = player.CharacterAdded:wait()
	end
	local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
	humanoidRootPart.Position = Vector3.new(-2, 1, -100)
end)

I’ve done some testing around and it seems the further away the player is from the point of teleport, the worse the movement becomes, any ideas why this is happening?

1 Like

Setting the HumanoidRootPart’s position is always going result in something like this.
The best way to move a character is to use the PivotTo() function.

In your case, I believe the server script would be:

local replicatedStorage = game:GetService("ReplicatedStorage")
local events = replicatedStorage:WaitForChild("events")
local teleport = events:WaitForChild("teleportPlayer")

teleport.OnServerEvent:Connect(function(player)
	local character = player.Character
	if not character or not character.Parent then
		character = player.CharacterAdded:wait()
	end
	
	character:PivotTo(CFrame.new(-2, 1, -100))
end)

Let me know if this sorts things out for you.

1 Like

use cframe and set their post to a parts position

like @6Marchy4 said. Use Pivot to.

Character:PivotTo(workspace.SpawnLocation.CFrame)

local part = part.CFrame

so to tp the user to the part do

script.Parent.Triggered:conncect(function(Player)
local cframe = Player.Character.PrimaryPart.CFrame
cframe:SetPRimaryCFrame(cframe)
end)

I did this at work so it may not work if not let me know and ill fix it when i get home.

Try anchoring the player before to starts and unanchor after!
I created a few examples for you in this place!!!
https://ro.blox.com/Ebh5?pid=share&is_retargeting=true&af_dp=roblox%3A%2F%2Fnavigation%2Fgame_details%3FgameId%3D2596030396&af_web_dp=https%3A%2F%2Fwww.roblox.com%2Fgames%2F6828211378
I hope this helps you! :wink:

never teleport by using position use pivot to like everyone said

for some reason roblox character’s primary part is now the head so it will pivot based off that so keep that in mind (:PivotTo works exactly the same as :SetPrimaryPartCFrame (deprecated))

That seems to be teleporting fine now however my character is now auto running, would there be any way to lock this auto run in 1 axis?

Surely you would have to change the value of autoRun, or something? I think the auto running is an issue in a part of code that you haven’t showed us because that definitely would not be happening normally

I’ll have a look to see if I can identify that.

1 Like

Sorry my bad, I must have forgot I changed the local script to this

inRace.Changed:Connect(function()
	if inRace.Value == true then
		if autoRun.Value == true then
			teleport:FireServer(player)
			RunService.RenderStepped:Connect(function()
				player:Move(Vector3.new(0,0,-16),true)
			end)
		end
	end
end)
1 Like

Ahhh awesome, good job on getting it to work!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.