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

[Solved] Mouse not snapping to grid?

Asked by
zblox164 531 Moderation Voter
6 years ago
Edited 5 years ago

I have a simple script where a model moves to the mouse position and when you click it places. My problem is I can't get the mouse to snap to a grid. Here is my movement script:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Part = workspace.Movement.PrimaryPart

Mouse.Move:Connect(function()
    local PosX = Mouse.Hit.X 
    local PosY = 11.1
    local PosZ = Mouse.Hit.Z

    Part.Parent:MoveTo(Vector3.new(PosX, PosY, PosZ))
end)

Mouse.Button1Down:Connect(function()
    local ClonedPart = Part.Parent:Clone()
    ClonedPart.Parent = workspace.Clones
    ClonedPart.PrimaryPart.Position = Part.Position
end)

I have tried a couple things to achieve my goal. 1. I have tried to add values to the Mouse position like this:

local PosX = Mouse.Hit.X + 0.5 -- My thoughts on this was that it would add enough movement that it would snap to a grid

It didn't work. I also tried it when I moved the model:

Part.Parent:MoveTo(Vector3.new(PosX + 0.5, PosY, PosZ + 0.5))
-- I don't want to snap the Y to grid

What I have: 1. Movement 2. Placement What I don't have: 1. Snapping the players mouse to a grid.

Thanks to who ever helps me!

0
I solved this one myself zblox164 531 — 5y

Answer this question