Mouse.Hit position snapping to random places (0,0,0?)

I’ve got a client-sided part that goes to my cursor whenever I move it, but it works inconsistently and will snap to a random position at random when it’s not moving. Sometimes it works fine, other times that happens.

I assume it’s to do with the server rejecting the part movement, but I’m not sure

BeamTargetPart = workspace.BeamTargetPart

Mouse.Move:Connect(function()
        BeamTargetPart.Position = Mouse.Hit.Position
end)

Lemme know if there’s a way to fix this or if there’s a better way to track the mouse movements. Using .Move might not be the play

1 Like

Have you tried printing mouse.Hit.Position ?

Yeah, I thought it was snapping to 0,0,0 but it actually goes to the bottom of the part in the same X and Z locations

The part that’s moving has cancollide and canquery both off so I’m not sure what’s causing it

Hmm, try setting the mouse.TargetFilter to BeamTargetPart and see the results

Same result unfortunately

I get the feeling it might be related to the fact that I’m making the part locally and using that and the server is rejecting it in some way

Hmm, strange, let me use studio to see if i could find a solution

like this only happens when you cursor is not moving. like check if other code is making the part go wonky

If the part is pre-made or created on the server side, it’s very likely that the part will snap back to its original position to prevent desync

i’ve tried it in the studio and it works fine, here is the script i used (i do not code clean, CanCollide is false and anchored is true)

local plrs=game:GetService('Players')
local mouse=plrs.LocalPlayer:GetMouse()
mouse.TargetFilter=workspace:WaitForChild('Part')
local past=vector.zero
local maxdistance=60
mouse.Move:Connect(function()
  if (plrs.LocalPlayer.Character.HumanoidRootPart.Position-mouse.Hit.Position).Magnitude>maxdistance then
    past=workspace:WaitForChild('Part').Position
  end
  workspace:WaitForChild('Part').Position=(plrs.LocalPlayer.Character.HumanoidRootPart.Position-mouse.Hit.Position).Magnitude<maxdistance and mouse.Hit.Position or past
end)

Yep, looks like anchoring it did the trick, thanks gamer

2 Likes

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