My killPart tween is tweening towards the camera instead of where it should go

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    So I made a projectile that uses a mouseRay using MouseLocation

  2. What is the issue? Include screenshots / videos if possible!
    the problem is that, the part is not going where it is intended to go to, it should go towards the npc but goes to the camera

as you can see, the part is going towards the camera, it should go to the npc instead, which is not what I want

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    First I tried using a subtracting head to mouse so it cannot be shot by a player that is facing the other way, but it didn’t work, I tried this
local headPosition = game.Players.LocalPlayer.Character.Head.CFrame.lookVector
local mouseLookCFrame = CFrame.new(game.Players.LocalPlayer.Character.Head.Position - mouse.Hit.p).LookVector
local mouseToHeadDistance = (headPosition - mouseLookCFrame).Magnitude
if mouseToHeadDistance < 1.3 then
    -- My code
end

then I tried using dev hub but nothing worked, I try to tween the part to the position

game:GetService("TweenService"):Create(killPart,TweenInfo.new(.5,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out,0,false,.1),{Position = position}):Play()

next I tried putting a negative sign of the goal but the part seems to go inside the ground and you have to be very close to the opponent to use it

Can you elaborate on what position refers to?

position refers to the position in the raycast

Do you just want the killPart to move to the player’s mouse position? If so, I believe you can just do

local Mouse = game.Players.LocalPlayer:GetMouse() -- call at top of script

local position = Mouse.Hit.Position

I want it towards the mouse but as you can see in the video, it moves towards screen instead, ill try it

doesn’t work, because I’m creating and tweening it in the server, It just puts it as nil when I try to pass it through the remote event

Instead of using a custom position, can’t you use Head.CFrame.LookVector.Unit instead?

{Position = Head.CFrame.LookVector.Unit * Magnitude}

as I said, it doesn’t work, it just calls it nil because its on the server, (passing it through the remote event)

get mouse.hit.p in the client and then give it to the server then give the target to it
if you said the script is server side just do that

now it’s fast and going through the npc

it works! Thanks! and thanks everyone for all the help

also
you might set target filter of the mouse to workspace and add touched event to it or anything possible
because if the plr moves away from the targeted pos of the bullet it will just stop there without hitting anything