The problem is: how can I make that it can move only in this grid and nowhere else?
Basically my buildings (models) can move only on that grid.
You can see 64 parts with decal on top of each of them.
How can I make a grid for that? How can I place a part on that grid?
I know I have to use UIS to render model in the cursorās position.
If youāve played Lumber Tycoon 2 or any other gamemode with blueprints then youād know what I want to achieve.
You could either make the whole game have a grid placing system by looking at the position the player has their mouse at and then floor that location to a grid offset. Or if your looking for aligning to a grid of predefined parts then check what the mouse is hovering over and move the thing you want to place on top.
I want something like this: Creating A Furniture Placement System
but simpler and working.
I tried cloning the part and setting the position to a cursor butā¦ how can I make it so its not outside of boundaries?
Iāll give my current script. How can I make it so that its only limited to the plotās boundaries. And can move only every 8 blocks (size of 1 tile in my grid).
local UIS = game:GetService('UserInputService')
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local root = script.Parent.Parent.Parent
local topPanel = root.TopPanel
local initSequence = ColorSequence.new({
ColorSequenceKeypoint.new(0, Color3.fromRGB(0,196,255)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(255,255,255)),
})
local buildingSequence = ColorSequence.new({
ColorSequenceKeypoint.new(0, Color3.fromRGB(255,190,0)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(255,0,0)),
})
local enabled = false
local xAreaConn: RBXScriptConnection
local mouseConn: RBXScriptConnection
local object: Part
local function disconnect()
xAreaConn:Disconnect()
mouseConn:Disconnect()
object:Destroy()
topPanel.Visible = false
enabled = false
script.Parent.UIGradient.Color = initSequence
end
script.Parent.MouseButton1Click:Connect(function()
if enabled then return disconnect() end
enabled = true
topPanel.Visible = true
script.Parent.UIGradient.Color = buildingSequence
object = game.ReplicatedStorage.Part:Clone()
xAreaConn = topPanel.XArea.MouseMoved:Connect(disconnect)
mouseConn = mouse.Move:Connect(function()
object.Position = mouse.Hit.Position
object.Rotation = Vector3.zero
object.Parent = workspace
end)
end)
Thatās literally what the post I linked talked about and showed (Placing in boundaries and in-game you can see the movement system. If itās too complicated for you and you just wonāt try to learn from it I donāt know how else to help you
The simplest way to tell it is that you need to round the position to the nearest grid tile and then check if thatās inside of the boundaries. If your boundaries arenāt aligned to grid, you may need to subtract their position and rotation to get local coordinates to round to.
I recommend just using the post @dummycide linked. You can use it straight up or learn from it to make your own.
u can make it so it checks if its outside certain position in x and z axis and to get it to be a grid use math.floor(number/10+gridsize/10) and times it by 10 later math.floor works by basically taking away the decimal point so for example if the grid is 4 studs per block and mouse is on 4.9 than it would go onto another grid however if it was on 4.5 it would stay at the previous block basically truncation
if you want to learn about math roblox has a developer thing which happens when you search up āroblox mathā it could help you with more things so yeah
if ur lazy hereās the link to it: https://developer.roblox.com/en-us/api-reference/lua-docs/math
yes, but they use Knit and other plugins which is making things 100 times more complicated.
Do you want a part placed on randomly on one of those parts?
No. I want to place my part on a part that the cursor points to.
If you move ur cursor to other tile in that grid then the part should ājumpā from the last tile to the new one.