So the CFrame.lookAt() thing seems to not work with meshParts but it does with normal Parts, so:
This works:
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local part = workspace.Part --This is a Part
while task.wait() do
CFrame.lookAt(part.Position, mouse.Hit.Position)
end
But this doesnt:
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local part = workspace.MeshPart --This is a meshPart
while task.wait() do
CFrame.lookAt(part.Position, mouse.Hit.Position)
end
Please tell me if this is normal or not, and if it is how can i work around it?
If the Mouse.Hit isn’t working as expected with MeshParts in Roblox, you might need to ensure that the MeshPart has a proper collision set up and that your script is correctly handling the Mouse object. Here’s a basic script to help you get started with making an object look at where the mouse is hitting, including handling MeshParts.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local objectToRotate = workspace.Object -- Replace with your object
mouse.Move:Connect(function()
local targetPosition = mouse.Hit.p
local objectPosition = objectToRotate.Position
local direction = (targetPosition - objectPosition).Unit
local newCFrame = CFrame.lookAt(objectPosition, targetPosition)
objectToRotate.CFrame = newCFrame
end)
Make sure to:
Set the Object: Replace workspace.Object with the path to the object you want to rotate.
Collision Settings: Ensure that the MeshPart or any other part has proper collision settings enabled so that the Mouse.Hit can register hits on it.
Position Handling: The script assumes the object is not anchored. If it is anchored, you might need additional logic to rotate it appropriately.
Troubleshooting Tips:
Check Collision: Verify that the MeshPart has its CanCollide property set correctly to allow the mouse to register hits.
Print Statements: Use print statements to debug and check values of mouse.Hit and objectToRotate.Positionto ensure they are what you expect.
Parent-Child Relations: Ensure that the object you are trying to rotate is properly parented in the workspace.
If the script still does not work as expected, let me know the specific behavior you’re observing, and I can help you further troubleshoot the issue.