SliderService - Create easy and functional Sliders!

Hey there, I’m trying to use this module for a settings menu, but the slider seems to get stuck when I try to move it with the mouse (works fine if I change the value directly), any clue what could be causing this?

3 Likes

Hm, mind dm’ing me the code you have, or a copy of the slider UI? Do you have the latest version aswell? I need to add a way to distinguish this lol

2 Likes

Sure, here’s the file
Slider thing.rbxl (53.0 KB)

I’m using the version linked the post
https://www.roblox.com/library/6460129603/LayoutUtil-v2

2 Likes

Thanks! Will check it out and see if I can find any bugs to why this happens lol

2 Likes

Issue found! Whenever :OverrideValue() was used, it sets IsHeld to false. Now, there are two ways you can fix this.

  1. I just remove that function that sets IsHeld to false, this could be bad as if the value is overridden, the slider could just move back into place when the mouse is moved.

  2. You can fix your code, which I’ve figured out why it happens:


    On line 45 you keep track of whenever the object’s volume property changes, and you then override the slider’s value. However, on line 48, you say when the slider changes value, to set its volume to the new value, this then fires the :GetPropertyChangedSignal function, causing a loop.

I’m not exactly sure how you can fix this, but one thing I would do is make a separate function which overrides the value and only call that when needed.

3 Likes

Ah I see, thank you for the quick response, I’ll see how I get it fixed later


Edit
Here’s the solution in case anyone comes across the same issue:

--local IsSliding = false --Nvm just use IsHeld

--My Value, used by the slider, changed. I want to update my slider.
Object:GetPropertyChangedSignal("Volume"):Connect(function()
	if Slider.IsHeld == false then --But only if slider isn't being held
		Slider:OverrideValue(Object[SliderString])
	end
end)

--My Slider changed, update my value.
Slider.Changed:Connect(function(Value)
	Object[SliderString] = Value
end)

-- Updates bool to prevent loop
--Slider.Dragged:Connect(function()
--	IsSliding = true
--end)
--Slider.Released:Connect(function()
--	IsSliding = false
--end)

Fyi, you can check Slider.IsHeld to see if the slider is being held!

1 Like

Update!
Sorry for taking so long to release this, I was really busy with school! (Aka I’m a lazy idot and need to work more)

Anyway:
:notebook_with_decorative_cover: Additions :notebook_with_decorative_cover:

  • Added SurfaceGui Support!!! :partying_face:

SurfaceGui Support is here!! The way it works is the exact same as creating a normal slider.
image
The only difference is that the module will instead detect what you are using, whether it be a surface gui or a screen gui, it will adapt accordingly. (Please don’t murder me this code can be neater!)
image

The module will also perform a raycast when using a surface gui, this is necessary in order to detect where the heck you’re pointing at!

If you want to find out how I did this, look at the :Update function in lines 224-281 (iirc)

Credit to this post below because otherwise I would have been very stuck lol:

1 Like

Bug fix!
:spiral_notepad: Changes :spiral_notepad:
A quick little bug fix I made was getting the surface gui to work on all sides, before writing this, it would bug out on any side that wasn’t the front. This was due to how I calculated the top left corner of the side to figure out where the mouse position was (that sounds complicated, trust me it’s not).

image
(For reference, topLeftCFrame used to be a different calculation which bugged out)

Anyways, this is now fixed!

PS: Just fixed another bug with surface guis, the module would calculate the mouse offset wrong for the X and Z axis on surfaces other than the front and back, also fixed!

1 Like

Crazy to see you’re still maintaining since the initial release. This is a very nice utility, and it is something I am definitely going to recommend to my friends in the future. Keep up the good work!

1 Like

Thank you! If you have any other requests for me to add things/change stuff please let me know haha

1 Like

Bug fix #2
I seriously need to learn to rigorously test my stuff before releasing it :man_facepalming: .
Just fixed a bug where the Y axis wasn’t calculated properly on surface guis, this was due to an issue with converting the mouse offset.

Anyways, fixed aswell.

Looks professional and customizable. I will definitely be bookmarking this whenever I find a use case. Thanks for making this.

2 Likes

does the OverrideValue() works if the value is changing like;(TimePosition of playing music)

1 Like

No problem! Any features or issues you have please let me know

1 Like

Yes, that’s actually one of the first things I made with it!

1 Like

i absolutely love this module
but i do wish there was an option to connect a progress bar to the slider
https://gyazo.com/bbf0a1e9bf92f96a76c0d2002e67dc3c
music slider i made (looks like spotify)

Thank you haha, I’m a bit unsure what you mean by connect a progress bar? You could do that with :OverrideValue()

i don’t know the proper name for it

This can cause a C stack overflow, depending on circumstance

Slider.__index = function(object, indexed)
	local deprecated = {
		{".OnChange", ".Changed", object.Changed} -- This indexes itself infinitely
	}

	for _, tbl in ipairs(deprecated) do
		local deprecatedStr = Sub(tbl[1], 2)

		if deprecatedStr == indexed then
			warn(Format("%s is deprecated, please use %s instead", tbl[1], tbl[2]))
			return tbl[3]	
		end
	end

	return Slider[indexed]
end

You need to change that line into this:

{".OnChange", ".Changed", rawget(object, "Changed")}
2 Likes