Answered by
6 years ago Edited 6 years ago
You will need to get set up first. Create a Model
with a PrimaryPart
. You can assign a PrimaryPart
by clicking PrimaryPart
in the properties menu. Then click on the object you want to be the PrimaryPart either in the explorer or the game view. You will want to put a LocalScript
in a client side service such as StarterGui
orReplicatedFirst
(I have mine in StarterGui
and it works fine). Here is a basic grid system example:
01 | local Model = workspace.Model |
04 | local Player = game.Players.LocalPlayer |
05 | local Mouse = Player:GetMouse() |
07 | Mouse.Move:Connect( function () |
08 | Mouse.TargetFilter = Model |
13 | local PosX = math.floor(Mouse.Hit.X / GridSize + 0.5 ) * GridSize |
14 | local PosY = Mouse.Hit.Y |
15 | local PosZ = math.floor(Mouse.Hit.Z / GridSize + 0.5 ) * GridSize |
19 | Model:MoveTo(Vector 3. new(PosX, PosY, PosZ)) |
Mouse.Hit.axis
is your mouse position on that axis. MoveTo
moves the model to a Vector3
value. As for the rounding it centers it with in the grid of 2 studs which you can change by changing the GridSize
variable.
If you just want the grid to be 1x1x1 then an even simpler solution is required:
1 | PosX = math.floor(Mouse.Hit.X) |
As for placing goes there is an event that you can use. Mouse.Button1Down
should work. Example:
1 | Mouse.Button 1 Down:Connect( function () |
2 | local PlacedModel = Model:Clone() |
Hopefully this helps!