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

how to make a dragable object with a grid?

local Fruittilium = game.Workspace.Fruittilium
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local down = false
Mouse.Button1Down:connect(function()
    down = true
    if Mouse.Target == Fruittilium then
    local Fruit = Fruittilium:Clone()
    Fruit.Parent = game.Workspace
    Fruit.Name = "ACOFruit"
    Fruit.Anchored = true
    Mouse.TargetFilter = Fruit
while true do
	Fruit.Position = Vector3.new(Mouse.hit.p.x, Mouse.hit.p.y, Mouse.hit.p.z)
    if down == false then
	Fruit:Destroy()
	Mouse.TargetFilter = nil
	break
end
    wait(.01)
	end
end
end)
Mouse.Button1Up:connect(function()
	down = false
end)

this script allows me to move objects freely.... too freely is there a way to add a grid to the object moves like one stud at a time?

1 answer

✓ Accepted answer

The easiest way to do this is math.floor() or math.ciel()

local Fruittilium = game.Workspace.Fruittilium
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local down = false
Mouse.Button1Down:connect(function()
    down = true
    if Mouse.Target == Fruittilium then
    local Fruit = Fruittilium:Clone()
    Fruit.Parent = game.Workspace
    Fruit.Name = "ACOFruit"
    Fruit.Anchored = true
    Mouse.TargetFilter = Fruit
while true do
    Fruit.Position = Vector3.new(math.floor(Mouse.hit.p.x), math.floor(Mouse.hit.p.y), math.floor(Mouse.hit.p.z)) -- Adding the math.floor() will round it down to the nearest whole number therefore placing it on a stud. Unless you want it to be in the exact center in which case you would need to add or subtract 0.5 from each number.
    if down == false then
    Fruit:Destroy()
    Mouse.TargetFilter = nil
    break
end
    wait(.01)
    end
end
end)
Mouse.Button1Up:connect(function()
    down = false
end)

Hope this helps! If you have any questions feel free to ask.

3 comments

0

Did this fix the problem you were having?

0

thnx soo much

0

Yeah no problem. If you have any other questions feel free to message me on roblox and ask for help

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