How do i make a gui that you can drag across the screen, and when you drop it on another gui, it snaps onto that position, and if you drag onto an empty space, it snaps back to its original position?
I couldn’t find anything on the devforum that regards the snapping
Can you give more details about what you mean, ideally a video example?
What exactly do you need this for? Is it some kind of inventory system or something?
So i’m trying to make this card game, where you get given 3 cards. You put these cards on a space on a grid. So what i want is to be able to grab one of the cards you were given, and put it onto the grid. Is this detailed enough? Making a video right now would take some time.
You can detect if the distance between both the GuiBase.AbsolutePosition are less than a certain threshold. If they are when releasing, you can initiate a snap-into-place effect.
What about the dragging though? how do i make that?
There was another DevForum post about it when Roblox deprecated the Draggable property.
You could just loop the grid, then connect the function MouseEnter, also connect it with the main frame but this time its MouseLeave, inside this functions (you first have to make a global variable) on the enter, set the global variable to the frame/button etc., or whaf type of ui you used, then on the leave set it nil. Once you have released the mouse, set the selectedFrame to the global variable. Sorry I can’t explain it to you properly Im on my phone.
The dragging can be done on the uis(user input service) or the mouse(player:GetMouse()).
Its better to use uis since it supports mobile, you need to connect the InputChanged for when the mouse moves, InputBegan and InputEnded.
detect when a gui is clicked or when mousebutton1 is pressed down, either clone the gui to make a moving version of it or actually move the gui iteself, while mousebutton1 is down or gui is attached to the mouse move the gui as the mouse moves, when mousebutton1 is no longer down detect if there is a place to put the gui underneath the mouse, place if true
you can make use of StarterGui:GetGuiObjectsAtPosition() to detect whether there is a place to put the dragged gui, if you plan to place it onto another gui