Tweening breaks CFrame Lookat()?


GIFs of the rotation with and without the tweening
Is there any way to circumvent this?

game.ReplicatedStorage.TweenPosition.OnClientEvent:Connect(function(PositioningData,Rotate)
	local Hash, X, Z = Decoder(PositioningData)
	local Army = game.Workspace.Armies:FindFirstChild(tostring(Hash))
	local ArmyInfo = game.Workspace.ArmyInfos:FindFirstChild(tostring(Hash))
	local Goal = {CFrame = CFrame.new(X,3,Z)}
	
	TweenService:Create(Army.PrimaryPart, TweenInfo.new(2, Enum.EasingStyle.Linear), Goal):Play()
end)

game.ReplicatedStorage.RotateArmyY.OnClientEvent:Connect(function(v,mouse)
	
	local Army = game.Workspace.Armies:FindFirstChild(v.Name)
		
	local Lookat = Vector3.new(mouse.X,1.5,mouse.Z)
	
	print(CFrame.lookAt(Army.PrimaryPart.Position, Lookat))
	
	Army.PrimaryPart.CFrame = CFrame.lookAt(Army.PrimaryPart.Position, Lookat)
end)

Any help would be appreciated.

Why do you have this hash and decoder?

Edit: it would also help to see the client side that calls the remote event

Hash and Decoder are for rendering the NPC’s model on the client

And the client calls on the remote event every time he clicks

Yeah but what’s the point in adding that complexity and sorry I meant the server side which calls the client I didn’t realise that the code snippet was on the client side

Dude do you know how to work around tweens breaking the army models rotation or not?

I need to understand how your code is working and also why you have added un reasonable complexity, if your not willing to share your code snippets when someone asks and also answer questions about your code you are in the wrong place.

I send the X, Z positions on the army’s Position to the client. But before I do that I simplify the positions using Vector2int16() to send less data and reduce kb/s. Afterwards the position will look like (16,19) when it should be like (16.365,18.97676) the Decoder is there to smoothen out the movement. Hash represents the armys special ID so I can find the army quickly.

local COORD_MULTIPLIER = 5
local function Decoder(PositioningData)	
	local Block1 = PositioningData[1]
	local Block2 = PositioningData[2]

	local Hash = Block1.X
	local X = Block2.X / COORD_MULTIPLIER 
	local Z = Block2.Y / COORD_MULTIPLIER 

	return Hash, X, Z
end

And without using CFrame.lookAt the decimals are retained?

CFrame.lookat dosnt use the decoder vector2int16() stuff

game.ReplicatedStorage.RotateArmyY.OnClientEvent:Connect(function(v,mouse)
	local Army = game.Workspace.Armies:FindFirstChild(v.Name)
	local Lookat = Vector3.new(mouse.X,0.5,mouse.Z)
	Army.PrimaryPart.CFrame = CFrame.lookAt(Army.PrimaryPart.Position, Lookat)
end)

Vector2int16() doesn’t allow decimals

This is due to it representing signed 16bit integers

I know. that’s why I have the decoder to smoothen out movement so it doesn’t look wonky

local COORD_MULTIPLIER = 5 
local function Encoder(Hash,X,Z)
	X = math.floor(COORD_MULTIPLIER * X + 0.5)
	Z = math.floor(COORD_MULTIPLIER * Z + 0.5)

	return {
		Vector2int16.new(Hash),
		Vector2int16.new(X, Z)
	}
end

This is the Encoder btw

Just use the normal v2 many games send many cframes per frame to the server vice versa
so just try use a normal v2

Bro it already works, i just need to fix this tween breaking

Im trying to help you debug the issue here, your just being rude for no reason

Ok I apologize, But whenever I rotate the army model, its completely fine and faces the direction I clicked in. But whenever I start tweening it, it goes back to staring straight or just completely breaking. Do you have any idea as of why this is happening?

What’s the code you use without tweening

game.ReplicatedStorage.RotateArmyY.OnClientEvent:Connect(function(v,mouse)
	local Army = game.Workspace.Armies:FindFirstChild(v.Name)	
	local Lookat = Vector3.new(mouse.X,0.5,mouse.Z)
	Army.PrimaryPart.CFrame = CFrame.lookAt(Army.PrimaryPart.Position, Lookat)
end)

I disable the TweenPosition remote, so when i click it only sends RotateArmyY remote. Result:

Ah I see so when you use tweening you lose the rotational component, for this you need to collapse the two events into 1 or have 1 for Moving and look and have one for just moving heres a code snippet for what to tween into

 local x,z = decoder(blah)
local x,y,z = CFrame.LookAt(Vector3.new(x,3,z),Vector3.new(mouse.X,1.5,mouse.Z)):ToEulerAnglesXYZ()

local finalCf = CFrame.new(Vector3.new(x,3,z)) * CFrame.Angles(x,y,z)

-- tween using the finalCf

maybe use coroutines? maybe its moving forward, looking at your mouse, moving forward