Tweening in one direction set by mouse

So, hi there! I need help with tweening.

I need to move a part from point a to point B with direction set by a players mouse.
(It’s a tool, which part comes out of a tip of tool and goes in direction set by players mouse)

But the thing is I would like to make part which will just go straight on and won’t stop.

Here’s a sample script to get you started:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local TweenService = game:GetService("TweenService")

-- Create the part
local part = Instance.new("Part")
part.Size = Vector3.new(1, 1, 1)
part.Position = player.Character.Head.Position
part.Anchored = true
part.Parent = workspace

-- Function to move the part
local function movePart()
    local direction = (mouse.Hit.Position - part.Position).unit
    local goal = {}
    goal.Position = part.Position + direction * 1000 -- Move far in the direction

    local tweenInfo = TweenInfo.new(10, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
    local tween = TweenService:Create(part, tweenInfo, goal)
    tween:Play()
end

-- Connect the function to mouse click
mouse.Button1Down:Connect(movePart)

This script will create a part and move it in the direction of the mouse click. The part will move continuously in a straight line. You can adjust the 1000 value to change how far the part moves.

1 Like

Thank you! Everything works just fine! Have a nice day, Sir.

1 Like

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