Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

how to make a dragable object with a grid?

Asked by 8 years ago
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

Log in to vote
0
Answered by 8 years ago

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.

0
Did this fix the problem you were having? MrLonely1221 701 — 8y
0
thnx soo much DrPredablox 153 — 8y
0
Yeah no problem. If you have any other questions feel free to message me on roblox and ask for help MrLonely1221 701 — 8y
Ad

Answer this question