How can I make a draggable thing like this?

So I am making a custom animator and Im at the point where I need to make it so you can change what time you are editing at, so I need to make it so you can drag a thing that changes the time to its position basically.


For instance in blender:


You can see that there is a blue thing, you can drag this thing around and it changes the time you are editing at.

Now I already know how to get the time depending on where that draggable thing is but I dont know well, how to make it draggable.

Extra notes

This is where it is positioned in the workspace:
Screenshot 2023-12-03 120108

btw the Animate frame is in a gui dont worry

If you know how to do this please feel free to tell me!

You can use UserInputService.InputBegan and UserInputService.InputEnded to detect when the mouse is held down and when it is released. From there, you can just make it follow the cursor’s position on the X axis.

2 Likes

this looks promising:

yes yes i know its old but according to the latest comment it appears to be working

1 Like

I agree with @FuntMaster here. You could use InputBegan and InputEnded with some checks, but I’d use the player’s mouse. Here’s an example

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Button = Draggable

local mouseMove
local mouseIn

Button.MouseEnter:Connect(function()
	mouseIn = true
end)

Button.MouseLeave:Connect(function()
	mouseIn = false
	if mouseMove then mouseMove:Disconnect() end
end)

Mouse.Button1Down:Connect(function()
	if mouseIn then
		mouseMove = Mouse.Move:Connect(function()
			if not mouseIn then return end
			Button.Position = UDim2.new(0, Mouse.X, 0, 0)
		end)
	end
end)

Mouse.Button1Up:Connect(function()
	if mouseMove then
		mouseMove:Disconnect()
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.