I need get the distance from the center of an object to the mouse click position, I can, but if I go to the other side of the object the value turns negative, and I need identify if the click was at left or right of the object's center, so I cant use the value signal to do this, I hope you can help me: image
I'm using this to get the value
mouse.Hit:toObjectSpace(object.CFrame).p.X
You can use the math function math.abs()
to construct a new Vector3 from the absolute value of each components of the p
vector and then retrieve it's X
component:
local tool = script.Parent local function onButton1Down(mouse) local part = mouse.Target -- Just to make sure the mouse isn't pointing nowhere or at the baseplate if part and part.Locked == false then local vec = mouse.Hit:toObjectSpace(part.CFrame).p print(Vector3.new(math.abs(vec.x), math.abs(vec.y), math.abs(vec.z)).X) end end local function onEquipped(mouse) mouse.Button1Down:connect(function() onButton1Down(mouse) end) end tool.Equipped:connect(onEquipped)
Hope this helps. If it did, please leave an upvote and mark my question as answered. :) If you need anything else, leave me a message.