Im Trying to make a custom grid placement system without the use of the tutorials that i dont understand and to see if I can simplify it so,
--The script is small local player = game.Players.LocalPlayer local mouse = player:GetMouse() local Grid = game.Workspace.Grid local GridSize = .5 local Marker = game.Workspace.Marker local PosX = Marker.CFrame.X local PosY = Marker.CFrame.Y local PosZ = Marker.CFrame.Z mouse.Move:Connect(function() if mouse.Target == Grid then mouse.TargetFilter = game.Workspace.Marker Marker.Position = Vector3.new(math.floor(mouse.Hit.X / GridSize + .05), mouse.Hit.Y, math.floor(mouse.Hit.Z / GridSize + .05)) end end)
So Here is the Grid issue The marker goes off the actual grid how does one prevent that
The problem with the marker being far away from the mouse is simple! Try the script below. Now, if your trying to make the marker stay in the plot/grid, then you should either use region3 or detect when the object is at the edge. I could not figure out which problem was yours based off the video given. Anyway, try the code below to fix the one problem.
local runService = game:GetService("RunService") local player = game.Players.LocalPlayer local mouse = player:GetMouse() local marker = game.Workspace.Marker local grid = game.Workspace.Grid local gridSize = 0.5 local yPos = 2 local positions = {} local function CalcMousePos() -- I am using an array of positions so I can easily access them later positions = { ["x"] = math.floor(mouse.Hit.X / gridSize + 0.5) * gridSize; ["z"] = math.floor(mouse.Hit.Z / gridSize + 0.5) * gridSize } end -- Moves the marker local function MoveMarker() mouse.TargetFilter = marker marker.CFrame = CFrame.new(positions.x, yPos, positions.z) end -- Updates every rendered frame runService.RenderStepped:Connect(function() CalcMousePos() MoveMarker() end)