I'm having trouble scripting this settings slider using Ui Drag detecter

I’m trying to me a settings ui for my game and i’m using UI Drag detecters for the sliders following a tutorial I made the code to make a percentage between 0 and 1 but its not working right can someone please help?

Code:

local Frame = script.Parent
local ScrollFrame = Frame:WaitForChild("ScrollFrame")
local Music = ScrollFrame:WaitForChild("Music")
local Buttion = Music:WaitForChild("Bar"):WaitForChild("Buttion")
local Num = -22

local num = Buttion.Position.X.Offset/453

Buttion:GetPropertyChangedSignal("Position"):Connect(function()
print(num)
end)

Video:


the percentage is supposed to display on the output buts its displaying a weird number

your variable is defined at the top, its not defined in the function, so it’ll always stay the same

local Frame = script.Parent
local ScrollFrame = Frame:WaitForChild("ScrollFrame")
local Music = ScrollFrame:WaitForChild("Music")
local Button = Music:WaitForChild("Bar"):WaitForChild("Buttion")

Button:GetPropertyChangedSignal("Position"):Connect(function()
    local num = Button.Position.X.Offset / 453
    print(num)
end)

Thats for helping it fixed the problem but Now I have a new one

local Frame = script.Parent
local ScrollFrame = Frame:WaitForChild("ScrollFrame")
local Music = ScrollFrame:WaitForChild("Music")
local Button = Music:WaitForChild("Bar"):WaitForChild("Buttion")

Button:GetPropertyChangedSignal("Position"):Connect(function()
    local num = (453 - Button.Position.X.Offset) / 453
    print(num)
end)

this might work lmk if it does

1 Like

I found a solution by changing the buttions position when the player joins