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

How to get a GUI to follow the mouse?

Asked by 10 years ago

Ok so basically, if any of you helpers out there might have played 'Roblox Battle!' by the admin team account 'Games' then you will basically know what I am talking about if you look at their inventory system. You can drag and drop your armor from your inventory onto an open spot on your character, which is basically what I am trying to do. I've looked at their scripts and I am not trying to do anywhere near as much as their doing and I tried to copy some of their code and apply it to mine but with no luck. Here is some of my code -

v.MouseButton1Down:connect(function()
    print(v.Name .. " was clicked!")
    local org_size = v.Size
    local org_pos = v.Position
    v.MouseMoved:connect(function(x, y)
        local x, y = Mouse.X, Mouse.Y
        local px, py = script.Parent.AbsolutePosition.X, script.Parent.AbsolutePosition.Y
        v.Position = UDim2.new(0, x-PAGE_ITEM_WIDTH, 0, y-PAGE_ITEM_HEIGHT)
        print(x-v.Parent.Parent.AbsolutePosition.X/2)
        print(y-v.Parent.Parent.AbsolutePosition.Y/2)
        print(Mouse.X .. " .. " .. Mouse.Y)
    end)
end)

the "x-PAGE_ITEM_WIDTH" thing came from Roblox Battle and it still doesn't help. What IS happening is that if I do :TweenPosition instead the GUI goes down below the viewable screen in the middle so like [ -|- ] in a way... I cannot explain it well. Anyway, please help, thanks!

  • ALSO - This isn't meant to use the draggable property if anyone was going to hint that, but thanks!

1 answer

Log in to vote
1
Answered by 10 years ago

I realize that you said it wasn't meant to use the draggable property, but that is simply put, the easiest way to do it for this case. Overcomplicating things is fun though. Try making the cursor the parent of the GUI part when the user clicks on it, and when they let go of the button it's parent becomes the GUI again. Just a thought.

Ad

Answer this question