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

Move model to mouse in studs?

Asked by 6 years ago

I made a script that when you click a GUI button, it will clone an object and allow you to place it somewhere. The script works, the object follows the mouse until clicked again and then is placed where it needs to be, however I need it to move like a grid such as like miners haven.

local debounce = false
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local objects = game.ReplicatedStorage.Objects
local ob = script.Parent.Object
script.Parent.MouseButton1Click:connect(function()
    if debounce == false then
        debounce = true
         part = objects:FindFirstChild(ob.Value)
            if part then
                part.Position = Vector3.new(0,0,0)
                clone = part:Clone()
                clone.Name = "Clone"
                clone.Parent = game.Workspace
                local owner = Instance.new("StringValue", clone)
                owner.Name = "Owner"
                owner.Value = game.Players.LocalPlayer.Name
                local object = Instance.new("StringValue", clone)
                object.Name = "Object"
                object.Value = script.Parent.Object.Value
            end
    end
    end)
function mouseMove()
    if debounce == true then
    local posX,posY,posZ = mouse.hit.X, mouse.hit.Y, mouse.hit.Z
    clone.Position = Vector3.new(posX,posY,posZ)
end
end
mouse.Move:connect(mouseMove)

mouse.Button1Down:connect(function()
    if debounce == true then
        debounce = false
    end
end)

Any help would be appreciated. -Wizy

0
math.floor() http://wiki.roblox.com/index.php?title=Global_namespace/Mathematical_functions&redirect=yes#math.floor theCJarmy7 1293 — 6y
0
there is a huge equation for studs... greatneil80 2647 — 6y

Answer this question