You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Whenever the user holds W, the offset value should go up. When the user holds S, the offset value goes down. Offset should be clamped between 45 and -45
-
What is the issue? The offset value can’t go above 0.
-
What solutions have you tried so far? Tried removing the clamps, deleting things, etc.
UserInputService.InputBegan:Connect(function(input, gpe)
if gpe then
return
end
local character = Player.Character
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
local seatedPart = humanoid and humanoid.SeatPart
if seatedPart and seatedPart:IsA("VehicleSeat") then
if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.S then
isKeyPressed[input.KeyCode] = true
while isKeyPressed[input.KeyCode] do
local YOffset = script.Parent.Reverser.TextButtona.Position.Y.Offset
local Button = script.Parent.Reverser.TextButtona
if input.KeyCode == Enum.KeyCode.W then
Button.Position = UDim2.new(0.5, 0, 0.5, (Button.Position.Y.Offset - 0.35))
elseif input.KeyCode == Enum.KeyCode.S then
Button.Position = UDim2.new(0.5, 0, 0.5, (Button.Position.Y.Offset + 0.35))
end
local percentage = 100 - math.round((Button.Position.Y.Offset - 0.5) * 100)
local clampedPercentage = math.clamp(percentage, 0, 100)
currentReverser = clampedPercentage - 50
task.wait(0.01)
end
end
elseif input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.D then
end
end
end)