So I've been trying to make the character face towards the mouse cursor when activating a tool. I wanted to interpolate the changing of the CFrame and make it a tween so there's a slight interpolation before the character rotates towards the cursor, making it overall look and feel nicer.
I've ran into a problem with my tween constantly playing itself in the Heartbeat loop and I need it to play with the Time parameter only once and then you could say the Time parameter is 0.
This is my code:
local tool = script.Parent
local camera = game:GetService("Workspace").CurrentCamera
local runService = game:GetService("RunService")
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local toolActivated = false
local mouse = plr:GetMouse()
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
tool.Activated:Connect(function()
toolActivated = true
end)
tool.Deactivated:Connect(function()
toolActivated = false
end)
runService.Heartbeat:Connect(function()
if toolActivated then
local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
local HRPpos = HumanoidRootPart.Position
local goal = {}
goal.CFrame = CFrame.new(HRPpos, Vector3.new(mouse.Hit.Position.x, HRPpos.y, mouse.Hit.Position.z))
local tweenInfo = TweenInfo.new(0.1)
local lookTween = TweenService:Create(HumanoidRootPart, tweenInfo, goal)
lookTween:Play()
end
end)
As you can see, I have made a variable containing tween information for a tween I made. I need to somehow find a way to change it after the tween plays for the first time when you only activate the tool so that the 0.1 I wrote (Time parameter) is 0 the second time the tween runs so that there is no interpolation. How can I achieve that?

4 comments
It could be also useful if there is a way to just prevent the player from interrupting the tween if they press any other movement keys to strafe, making the tween replay and result in the player not facing the mouse.
I came to a conclusion that I just need to stop the Tween and then keep changing the CFrame constantly but now I've got another problem which is that there's a jittery delay when the tween happens and it stops the character in place and then you can walk again. https://gyazo.com/3cf1ad4a90ebad6368931a24a94493e2 Here's a gif showing what I mean and my new code: https://pastebin.com/80N5jdtW
The reason being that you defined the HRP's position in the tween and so the HRP freezes in that spot for 0.1 second. Tweens aren't applicable to your situation
I see. Thank you.