Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My own Grid thing is a little odd how do i fix it?

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

2 comments

2

I think you've messed up the math.floor(mouse.Hit.X / GridSize + .05) and math.floor(mouse.Hit.Z / GridSize + .05) lines. Test with this instead: Vector3.new(math.floor(mouse.Hit.X - GridSize), mouse.Hit.Y, math.floor(mouse.Hit.Z - GridSize))

0

pls dont flag for spam but hi ankur <3 its ur boi

1 answer

✓ Accepted answer

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)

2 comments

0

i did figure it out but because your method did work ill accept

0

ok

This discussion is preserved as it was. New answers, comments, and votes are closed.