Hi, I’m writing a script that when a button is pressed changes the car’s throttle, and for that I’m using the TouchLongPress event, but it has a delay to execute the function when the person starts to hold it, and also when I hold a button, if I try to hold another button at the same time the other button doesn’t perform the function, only if I’m just holding it.
I need someone to help me solve these two problems mentioned above, please.
Here’s the code:
local acelerando = false
local freiando = false
script.Parent.Acelerar.TouchLongPress:Connect(function(tp, state)
print(vehicleSeat.ThrottleFloat)
if state == Enum.UserInputState.Begin or state == Enum.UserInputState.Change then
if freiando == false then
acelerando = true
task.spawn(function()
while acelerando do
task.wait()
vehicleSeat.ThrottleFloat = 1
end
return nil
end)
end
elseif state == Enum.UserInputState.End then
acelerando = false
vehicleSeat.ThrottleFloat = 0
end
end)
script.Parent.Freiar.TouchLongPress:Connect(function(tp, state)
if state == Enum.UserInputState.Begin or state == Enum.UserInputState.Change then
if acelerando == false then
freiando = true
task.spawn(function()
while freiando do
task.wait()
vehicleSeat.ThrottleFloat = -1
end
return nil
end)
end
elseif state == Enum.UserInputState.End then
freiando = false
vehicleSeat.ThrottleFloat = 0
end
end)
local direita = false
local esquerda = false
script.Parent.VirarDir.TouchLongPress:Connect(function(tp, state)
if state == Enum.UserInputState.Begin or state == Enum.UserInputState.Change then
direita = true
task.spawn(function()
while direita do
task.wait()
vehicleSeat.SteerFloat = 1
end
return nil
end)
elseif state == Enum.UserInputState.End then
direita = false
vehicleSeat.SteerFloat = 0
end
end)
script.Parent.VirarEsq.TouchLongPress:Connect(function(tp, state)
if state == Enum.UserInputState.Begin or state == Enum.UserInputState.Change then
esquerda = true
task.spawn(function()
while esquerda do
task.wait()
vehicleSeat.SteerFloat = -1
end
return nil
end)
elseif state == Enum.UserInputState.End then
esquerda = false
vehicleSeat.SteerFloat = 0
end
end)