Slider goes over the background frame

So i was creating a slider for the volume setting in my game, and when testin i noticed my slider goes over the bacground frame. I have no idea why it’s happening.

Here the code:

local Mouse = game.Players.LocalPlayer:GetMouse()
local Slider = script.Parent
local Fill = script.Parent.Fill
local Trigger = script.Parent.Trigger

local function UpdateSlider()
	local output = (Mouse.X-Slider.AbsolutePosition.X)/Slider.AbsoluteSize.X
	Fill.Size = UDim2.fromScale(output,1)
end

local sliderActivated = false


function ActivateSlider()
	sliderActivated = true
	while sliderActivated do
		UpdateSlider()
		task.wait()
	end
end


Trigger.MouseButton1Down:Connect(ActivateSlider)

game:GetService("UserInputService").InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		sliderActivated = false
	end
end)

Slider Video:

GUI structure

image

You haven’t set any limit to the size, try this :

Fill.Size = UDim2.fromScale(math.clamp(output, 0, 1),1)

Math.clamp() basically sets minimum and maximum limits to a number

1 Like

ooooh i see, yeah it works tysm :slight_smile:

If this works please mark my reply as solution so people will know that the problem is solved
Thank you

yeah i was waiting for your reply, again thank you

1 Like

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