How i can make it stop teleporting to my mouse position?

ari12

i want it stop teleporting to my mouse when button1up and i really get confused how to make that if someone can help me i will be happy

Put the part in the mouse’s TargetFilter. Also you will want to modify how your code is structured a bit.

https://developer.roblox.com/en-us/api-reference/property/Mouse/TargetFilter

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local T = game.Workspace.Mama

local Target

--// Ignore T's position when the mouse does a raycast to define mouse.Hit
mouse.TargetFilter = T

--// When the player is holding down their mouse set the target to what they're currently hovering on
mouse.Button1Down:Connect(function()
    Target = mouse.Target
end)

--// When they let go then reset the Target variable
mouse.Button1Up:Connect(function()
    Target = nil
end)

--// When they move their mouse, and Target == T then it will move T to the mouse's position. 
mouse.Move:Connect(function()
    if (Target == T) then
        T.Position = mouse.Hit.Position
    end
end)
1 Like

can you explain more where exactly? bc i little bit confused

I edited my post because I realized there is another issue.

Everytime mouse.Move while hovering your mouse over T it would also create a new mouse.Button1Down event. And everytime that was done it would create a new mouse.Move event inside that event. This is an insanely bad idea. You will want to structure the code differently

And if you want an explanation on mouse.TargetFilter, check the link I posted on my first reply.

https://developer.roblox.com/en-us/api-reference/property/Mouse/TargetFilter

This property determines an object to be ignored by the mouse when calculating Mouse.Hit and Mouse.Target . The descendants of the object are also ignored, so it is possible to ignore multiple objects so long as they are a descendant of the object to which this property is set. This property is useful when filtering models containing special effects or decorations that should not affect Mouse.Hit or Mouse.Target .

thank you very much, you helped me alot

still not work to me, it doing nothing