I have made a script that positions the block wherever my mouse is hovering in my game, but the block is glitching out and moving 'closer towards my screen'. Is there anyway to avoid this? Please do help if you have any ideas, thank you...
SCRIPT:
local Plrs=game:GetService("Players"); local Plr=Plrs.LocalPlayer; local Mouse=Plr:GetMouse(); local p=Instance.new("Part", workspace); p.Anchored=true; p.Size=Vector3.new(2,2,2); p.Locked=true; p.CanCollide=false; function snapToGrid(GridSizeX,GridSizeY,GridSizeZ,Vector) return Vector3.new(math.floor(Vector.X*0.5+0.5)*GridSizeX,math.floor(Vector.Y*0.5+0.5)*GridSizeY,math.floor(Vector.Z*0.5+0.5)*GridSizeZ); end game:GetService("RunService").RenderStepped:Connect(function() if(p) then p.CFrame=CFrame.new(snapToGrid(2,2,2,Mouse.Hit)); end end)
Run this in a localscript and move your mouse once the character loads and you'll see what my issue is.