SliderService - Create easy and functional Sliders!

I’m having an issue whenever I connect the changed event.

well I never tried Slider:Destroy() but I dont think there are easy ways to delete it but ima check out later when I have time

I solve this issue in my first reply

Hello, I’m having an issue using this for some reason when I hooked it up to a frame it never adds the array it suppose to inside of the changed any reasons why?

You should add a property to make AllowBackgroundClick fire the :Released() connection, I added this myself but it would be cool if you added it for people that would use this.

I love this! Can you add a option to add a frame that will follow behind the Slider GuiButton?

I am talking about the blue line in the video below.

2 Likes

you can easily do that with uigradients

1 Like

Not sure why I have this problem but whenever I create the slider and then open the game the slider seems to be invisible and only appears when I either click on the background or when I physically in studio go to playergui and click on the slider, and then it just randomly pops up again.

	-- Music volume
	local MusicVolumeSetting = ScrollingFrame:WaitForChild("MusicVolume")
	local FOVSlider = Slider.new(MusicVolumeSetting:WaitForChild("Holder"), {
		SliderData = {Start = 0, End = 100, Increment = 1},
		MoveInfo = TweenInfo.new(0.1, Enum.EasingStyle.Quad),
	})
	
	FOVSlider.Changed:Connect(function(newValue: number)
		_G.ActiveMusic.Volume = newValue / 100
		MusicVolumeSetting:WaitForChild("Holder"):WaitForChild("Slider").Text = newValue
	end)
	MusicVolumeSetting:WaitForChild("Holder"):WaitForChild("Slider").Visible = true
	FOVSlider:Track()
	FOVSlider:OverrideValue(50)

Amazing module! Thank you very much.

I have made a plugin for this module to make adding sliders easier for users.

1 Like

It’s private
image

Fixed. Should be on sale for free :slightly_smiling_face:

1 Like

what wrong with my script?

i try to use Changed in my script but this give error

ReplicatedStorage.Modules.Slider.Utils.Signal:51: invalid argument #1 to 'unpack' (table expected, got nil)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Slider = require(ReplicatedStorage.Modules:WaitForChild("Slider"))

local holderFrame = script.Parent.Frame
local currentCamera = workspace.CurrentCamera

local working = true

local boombox = game.Players.LocalPlayer.Character:WaitForChild("Boombox"):WaitForChild("Object").Value
local sound = boombox:WaitForChild("Sound")

function timel()
	repeat wait(0.05) until sound.IsLoaded
	if sound.TimeLength == 0 then
		return 0.5
	else
		return sound.TimeLength
	end
end

local TimeSlider = Slider.new(holderFrame, {
	SliderData = {Start = 0.1, End = timel(), Increment = 0.1},
	MoveInfo = TweenInfo.new(0.1, Enum.EasingStyle.Quad)
})

print(TimeSlider)

sound:GetPropertyChangedSignal("SoundId"):Connect(function()
	working = false
	TimeSlider:Destroy()
	print(TimeSlider)
	TimeSlider = Slider.new(holderFrame, {
		SliderData = {Start = 0.1, End = timel(), Increment = 0.1},
		MoveInfo = TweenInfo.new(0.1, Enum.EasingStyle.Quad)
	})
	TimeSlider:Track()
	working = true
end)

TimeSlider.Changed:Connect(function(newFov: number)
	workspace.CurrentCamera.FieldOfView = newFov
end)
TimeSlider:Track()

while wait(0.1) do
	--TimeSlider:OverrideValue(sound.TimePosition)
end

Quick FYI, I am going on a holiday for about a week or two however when I return I do plan on giving this module a backwards-compatible rewrite which should hopefully fix a lot of problems being reported

1 Like

You must note that the holder must be a descendant of PlayerGUI; otherwise, the scale will be read as NaN. I discovered this after an hour of debugging because the slider disappeared. It turns out the slider must be created after the holder is cloned into PlayerGUI. @Krystaltinan

Before

local holder = x:Clone()
local slider = SliderService.new(holder)
holder.Parent = player.PlayerGUI

image

After

local holder = x:Clone()
holder.Parent = player.PlayerGUI
local slider = SliderService.new(holder)

image

If I may suggest, please consider adding new signals like onBackgroundClick and possibly overridden, because relying solely on changed makes it somewhat difficult to determine what has changed and what caused it. Aside from that, this module is already excellent, although I had to make a few modifications to fit my specific needs.

1 Like

Hey, does anyone have a clue how to make it so you can start dragging from the background frame?

[Solved] If anyone’s interested, I just put this line of code:

table.insert(self._data._clickConnections, self._data.HolderButton.MouseButton1Down:Connect(function()
			self.IsHeld = true
end))

Here:

if self._data._allowBackgroundClick then
		table.insert(self._data._clickConnections, self._data.HolderButton.MouseButton1Down:Connect(function()
			self.IsHeld = true
		end))
		table.insert(self._data._clickConnections, self._data.HolderButton.Activated:Connect(function(inputObject: InputObject)
			if inputObject.UserInputType == Enum.UserInputType.MouseButton1 or inputObject.UserInputType == Enum.UserInputType.Touch then
				if self.IsHeld then
					self._data._inputPos = inputObject.Position
					self._data._clickOverride = true
					self:Update()
					self._data._clickOverride = false
				end
			end
		end))
	end

Hope it helps someone )

Slider.Changed fires constantly while dragging, not when the value actually changes?

Fixed this by using an oldValue variable:

slider.Changed:Connect(function(newValue)
	if newValue ~= oldValue then
		oldValue = newValue
		buttonSound:Play()
	end
end)