VIDEO OF ISSUE: https://medal.tv/games/roblox-studio/clips/p0L1D8tSf0-wW/d1337Y7Qpcl7?invite=cr-MSxOT2osMzg1NzgyMTEs
Hello, so my issue is when I click on the throttle UI and go down a little bit it goes down instantly to about half, which is not ideal as you can tell in any situation. It also when it goes down to 0 the UI does not go down all the way. I would like the UI to go down all the way when at 0 and when you go down it will slowly go down and not instantly go to half.
Here is the code.
-- The Mobile Throttle
local snapAmount = 5
local pixelsFromEdge = 0
local movingSlider = false
local mouse = Player:GetMouse()
local slider = script.Parent.Throttle.Slider
local sliderBG = script.Parent.Throttle
slider.MouseButton1Down:Connect(function()
movingSlider = true
end)
slider.MouseButton1Up:Connect(function()
movingSlider = false
end)
mouse.Button1Up:Connect(function()
movingSlider = false
end)
mouse.Move:Connect(function()
if EngineOn then
if movingSlider then
local xOffset = math.floor((mouse.Y - sliderBG.AbsolutePosition.Y) / snapAmount + 0) * snapAmount
local xOffsetClamped = math.clamp(-xOffset, pixelsFromEdge, sliderBG.AbsoluteSize.X - pixelsFromEdge)
local sliderPosNew = UDim2.new(0, xOffsetClamped, slider.Position.Y)
slider.Position = sliderPosNew
local roundedAbsSize = math.floor(sliderBG.AbsoluteSize.X / snapAmount + 0) * snapAmount
local roundedOffsetClamped = math.floor(xOffsetClamped / snapAmount + 0) * snapAmount
local sliderValue = roundedOffsetClamped / roundedAbsSize
local NewThrottle = math.floor(sliderValue*255)
if NewThrottle <= 24 then
Throttle = 0
elseif NewThrottle >= 225 then
Throttle = 225
script.PilotSeat.Value.MaxSpeed = 225
else
Throttle = NewThrottle
script.PilotSeat.Value.MaxSpeed = NewThrottle
end
end
else
Throttle = 0
end
end)
ThrottleUI.rbxm (4.8 KB)
Here is the throttle UI ^