So basically I have this slider and it functions perfectly however there is one issue. The first time I try to use it everything goes accordingly however it’s meant to stop sliding whenever the mousebutton1up is fired however when i go off the slider and go back onto it there is an issue. The slider keeps sliding despite me not clicking on it.
local BarDown = false
MusicProgress.MouseButton1Down:Connect(function()
BarDown = true
end)
MusicProgress.MouseButton1Up:Connect(function()
BarDown = false
end)
MusicSlider.MouseMoved:Connect(function()
if BarDown then
local Value = math.floor((((tonumber(365) - tonumber(minvalue)) / 365) * MusicSlider.AbsoluteSize.X) + tonumber(minvalue))
if (math.clamp(Mouse.X - MusicProgress.AbsolutePosition.X, 0, 365)) < 50 then
MusicSlider.Size = UDim2.new(0, Value, 0, 24)
end
MusicProgress.Size = UDim2.new(0, math.clamp(Mouse.X - MusicProgress.AbsolutePosition.X, 0, 365), 0, 24)
MusicValue.Text = tostring( (math.clamp(Mouse.X - MusicProgress.AbsolutePosition.X, 0, 365)/100) )..' / 3.65'
end
end)
try using game:GetService('UserInputService') your problem more likely the mouse isnt on the button anymore when you release it, so the MouseButton1Up wont fire
local uis = game:GetService('UserInputService')
uis.InputEnded:Connect(function(input,g)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
BarDown = false
end
end)
you can utilize the BarDown. if its true then the function will run and vice versa
local uis = game:GetService('UserInputService')
uis.InputEnded:Connect(function(input,g)
if input.UserInputType == Enum.UserInputType.MouseButton1 and BarDown then
BarDown = false
end
end)
If the Slider is a Frame then you can connect directly to it’s own InputBegan/InputEnded.
Here’s an example of a Slider that uses it when being dragged by MouseButton1 or Touch:
local UiS=game:GetService("UserInputService")
local Fr=script.Parent:WaitForChild("Frame")
local Slider=Fr:WaitForChild("Slider")
local isActive=false
local iMouse=Enum.UserInputType.MouseButton1
local iTouch=Enum.UserInputType.Touch
local function GetXPos(frame)
local minXPos=frame.AbsolutePosition.X
local maxXPos=minXPos+frame.AbsoluteSize.X
local xPixelSize=maxXPos-minXPos
local mouseX=(UiS:GetMouseLocation().X)
mouseX=math.clamp(mouseX, minXPos, maxXPos)
return (mouseX-minXPos)/xPixelSize
end
local function DragSlider()
repeat task.wait()
local xPos=GetXPos(Fr)
Slider.Position=UDim2.fromScale(xPos, .5)
until not isActive
end
Slider.InputBegan:Connect(function(i) if i.UserInputType==iMouse or i.UserInputType==iTouch then isActive=true DragSlider() end end)
Slider.InputEnded:Connect(function(i) if i.UserInputType==iMouse or i.UserInputType==iTouch then isActive=false end end)
GuiButtons also have their own InputBegan/InputEnded, I only mentioned Frame as it’s used in the example I posted - maybe I should’ve made that more clear.
There’s a problem with this though I already have it done for when they click or touch it. I need it to run while the players mouse is held over the progress bar so it can continously change size to wherever they move their mouse. Input began only fires once.