Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Setting part's position with Mouse is moving the block up more towards my camera? [SOLVED]

Asked by
Troxure 87
6 years ago
Edited 6 years ago

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.

1
Set the Mouse's TargetFilter to the part Rare_tendo 3000 — 6y
0
Thank you it worked Troxure 87 — 6y

Answer this question