CFrame teleporting is breaking in an unexplainable way

Hello. I’ve made a rope, where you can press E, and it teleports you to the other side, but for some reason, as you do it in the second time (>) it will break and teleport you somewhere.
Here is my code:

local remoteEvent = game.ReplicatedStorage.Rope;

local function server_Event(player, startedCFrame, endCFrame)
	local animation = script.Animation;
	local humanoid = player.Character.Humanoid;
	local track = humanoid:LoadAnimation(animation)
	
	track:Play()
	
	humanoid.WalkSpeed = 0
	humanoid.JumpPower = 0
	humanoid.Parent.HumanoidRootPart.Anchored = true
	humanoid.Parent.UpperTorso.CFrame = startedCFrame

	local tweenService = game:GetService("TweenService");
	local tweenInfo = TweenInfo.new(3);
	
	local goal = {
		Position = endCFrame
	};

	wait(0.25)
	
	tweenService:Create(humanoid.Parent.HumanoidRootPart, tweenInfo, goal):Play()
	
	wait(3)
	
	humanoid.Parent.HumanoidRootPart.Anchored = false
	track:Stop()
		
	wait(1)
	
	humanoid.WalkSpeed = 16
	humanoid.JumpPower = 50
end;

remoteEvent.OnServerEvent:Connect(server_Event)

Here is a video of what is happening: https://streamable.com/sgosj3

Client script (I do not find it necessary but you may do):

local billbaord = script.Parent;

local userInputService = game:GetService("UserInputService");

local lastUI = nil;

local lastInteractable = nil;

local function input_Began(input, isTyping)
	if isTyping then return end;
	
	local cancalled = false;
	
	if input.KeyCode ~= Enum.KeyCode.E then return end;
	
	local tweenService = game:GetService("TweenService");
	
	local tweenInfo = TweenInfo.new(0.2);
	
	local goal = {
		Size = UDim2.new(0.428, 0,0.866, 0);
		BackgroundColor3 = Color3.fromRGB(41, 82, 124)
	};
	
	tweenService:Create(lastUI.Around.Inside, tweenInfo, {
		BackgroundColor3 = Color3.fromRGB(41, 82, 124)
	}):Play()
	
	local track = tweenService:Create(lastUI.Around, tweenInfo, goal);
	
	track:Play()
	
	lastUI.Around.Inside.InsideBar.Size = UDim2.new(0.34, 0,0.363, 0)
	
	lastUI.Around.Inside.InsideBar.Visible = true
	
	local track2 = tweenService:Create(lastUI.Around.Inside.InsideBar, TweenInfo.new(0.2), {
		Size = UDim2.new(1, 0, 1, 0)
	})
	
	track2:Play()
	
	userInputService.InputEnded:Connect(function(input, isTyping)
		if isTyping then return end;
		
		if input.KeyCode == Enum.KeyCode.E then
			cancalled = true
			
			tweenService:Create(lastUI.Around, tweenInfo, {
				Size = UDim2.new(0.528, 0,1.006, 0);
				BackgroundColor3 = Color3.fromRGB(85, 170, 255)
			}):Play()
			
			tweenService:Create(lastUI.Around.Inside, tweenInfo, {
				BackgroundColor3 = Color3.fromRGB(85, 170, 255)
			}):Play()
			
			lastUI.Around.Inside.InsideBar.Visible = false
		else
		end
	end)
	
	local currentTIme = os.time();
	
	repeat wait()
		
	until cancalled == true or os.time() - currentTIme > 0.2
	
	if cancalled then
		print("Duration of holding E is shorter than the required, not firing remote events [Duration]")
	else
		if lastInteractable.Name == "LGBTQ" then
			game.ReplicatedStorage.AddToInventory:FireServer(lastInteractable:FindFirstChildOfClass("StringValue"))
		elseif lastInteractable.Name == "Rope" then
			game.ReplicatedStorage.Rope:FireServer(workspace.FirstRopeCFrameVector.CFrame, workspace.LastPartForCFrame.Position)
		end
		
		tweenService:Create(lastUI.Around, tweenInfo, {
			Size = UDim2.new(0.528, 0,1.006, 0);
			BackgroundColor3 = Color3.fromRGB(85, 170, 255)
		}):Play()

		tweenService:Create(lastUI.Around.Inside, tweenInfo, {
			BackgroundColor3 = Color3.fromRGB(85, 170, 255)
		}):Play()

		lastUI.Around.Inside.InsideBar.Visible = false
	end
end;

userInputService.InputBegan:Connect(input_Began)

while wait() do		
	local closestPoint = 7;

	local interactables = workspace.Interactables:GetChildren();
	
	if lastInteractable and (game.Players.LocalPlayer.Character.UpperTorso.Position - lastInteractable.Position).Magnitude > closestPoint then lastUI:Destroy() else end
	
	for _, v in ipairs(interactables) do
		if (game.Players.LocalPlayer.Character.UpperTorso.Position - v.Position).Magnitude < closestPoint then
			lastInteractable = v
			
			local clone = script.Interaction:Clone();
			
			clone.Parent = v;
			
			lastUI = clone
			
			repeat wait()
				
			until (game.Players.LocalPlayer.Character.UpperTorso.Position - v.Position).Magnitude > closestPoint
			
			lastUI:Destroy()
		else
		end
	end
end

The line where I fire the Remote Event in the Client script:

game.ReplicatedStorage.Rope:FireServer(workspace.FirstRopeCFrameVector.CFrame, workspace.LastPartForCFrame.Position)
2 Likes

That’s odd looking at the code it shouldn’t happen assuming this CFrame stays the same.

workspace.FirstRopeCFrameVector.CFrame

Otherwise, perhaps try defining your tween service out of scope as a constant variable instead of every time the connection plays like so, and using tween service completed maybe that is the cause?

Proposed above changes to script
--put constant services here
local tweenService = game:GetService("TweenService");

local remoteEvent = game.ReplicatedStorage.Rope;

local function server_Event(player, startedCFrame, endCFrame)
	local animation = script.Animation;
	local humanoid = player.Character.Humanoid;
	local track = humanoid:LoadAnimation(animation)
	
	track:Play()
	
	humanoid.WalkSpeed = 0
	humanoid.JumpPower = 0
	humanoid.Parent.HumanoidRootPart.Anchored = true
	humanoid.Parent.UpperTorso.CFrame = startedCFrame

	local tweenInfo = TweenInfo.new(3);
	
	local goal = {
		Position = endCFrame
	};

	wait(0.25)
	
	local ropeTween = tweenService:Create(humanoid.Parent.HumanoidRootPart, tweenInfo, goal)

ropeTween:Play()
	
--ensure tween is finished using the tween event
	ropeTween.Completed:Wait()
	
	humanoid.Parent.HumanoidRootPart.Anchored = false
	track:Stop()
		
	wait(1)
	
	humanoid.WalkSpeed = 16
	humanoid.JumpPower = 50
end;

Otherwise, another possible cause that may occur is tween conflict if the tween somehow still exists, and when the event happens twice something weird might happen I suggest checking that out.

2 Likes

Thank you for replying. :pray:
Unfortunately, your solution did not solve the problem.
Do you find anything else that may cause this problem?

1 Like

You must change Position to CFrame in the goal table.

local remoteEvent = game.ReplicatedStorage.Rope;

local function server_Event(player, startedCFrame, endCFrame)
local animation = script.Animation;
local humanoid = player.Character.Humanoid;
local track = humanoid:LoadAnimation(animation)

track:Play()

humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
humanoid.Parent.HumanoidRootPart.Anchored = true
humanoid.Parent.UpperTorso.CFrame = startedCFrame

local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(3);

local goal = {
	CFrame = endCFrame
};

wait(0.25)

local ropeTween = tweenService:Create(humanoid.Parent.HumanoidRootPart, tweenInfo, goal)

ropeTween:Play()

--ensure tween is finished using the tween event
ropeTween.Completed:Wait()

humanoid.Parent.HumanoidRootPart.Anchored = false
track:Stop()

wait(1)

humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
end;

remoteEvent.OnServerEvent:Connect(server_Event)