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