Hello Devs
I am pretty new to scripting so I cant make things like sliders and stuff, so I followed a tutorial on youtube that explained how to make this slider, but it has one problem.
Clicking anywhere on the slider makes it change value, like it should. But if I hold down my mouse button the value changes to a greater one for some reason. For example, if I hold down my cursor on 50, the value will be set to 75. The gif below shows what happens
this is the layout inside the explorer
this is the “Update” script
local mouse = game.Players.LocalPlayer:GetMouse()
local slider = script.Parent
local fill = script.Parent.Fill
local trigger = script.Parent.Trigger
local outputValue = script.Parent.OutputValue
local outputLabel = script.Parent.Label
local maxValue = 1 or 100/100
local startingValue = 0.5 or 50/100
fill.Size = UDim2.fromScale(outputValue.Value,1)
outputLabel.Text = tostring(math.round(outputValue.Value*100))
local tweenService = game:GetService("TweenService")
local tweenStyle = TweenInfo.new(0.25,Enum.EasingStyle.Exponential)
function UpdateSlider()
local output = math.clamp(((Vector2.new(mouse.X,mouse.Y)-slider.AbsolutePosition)/slider.AbsoluteSize).X,0,1)
local outputClamped = startingValue + (output*(maxValue-startingValue))
if outputValue.Value ~= outputClamped then
tweenService:Create(fill,tweenStyle,{Size = UDim2.fromScale(output,1)}):Play()
end
outputValue.Value = outputClamped
outputLabel.Text = tostring(math.round(outputValue.Value*100))
print(output)
end
local sliderActive = false
fill:GetPropertyChangedSignal("Size"):Connect(function()
outputLabel.Text = tostring(math.round(fill.Size.X.Scale*100))
end)
function ActivateSlider()
sliderActive = true
while sliderActive do
UpdateSlider()
task.wait()
end
end
workspace.MusicRandom:GetDescendants()
trigger.MouseButton1Down:Connect(ActivateSlider)
game:GetService("UserInputService").InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
sliderActive = false
end
end)
If anyone knows why that happens, please tell me why
Thanks