how can I make
when you press a button
something is activated
and when you press it again it is deactivated
I have done that by hitting the comma
to activate the limiter
but I want to make it turn off again
Try defining limiterState inside of the thread, before the while loop.
Citizen.CreateThread(function()
local limiterState
while true do
Citizen.Wait(0)
if IsControlJustReleased(0, 82) then
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local limiterSpeed = GetEntitySpeed(vehicle)
if not limiterState then
limiterState = true
SetEntityMaxSpeed(vehicle, limiterSpeed)
elseif limiterState then
limiterState = false
SetEntityMaxSpeed(vehicle, -100.0)
end
else
if limiterState then
limiterState = false
end
end
end
end)
--FUNCION DE LIMITADOR--
Citizen.CreateThread(function()
local limitador
while true do
Citizen.Wait(0)
if IsControlJustReleased(0, 82) then
local coche = GetVehiclePedIsIn(PlayerPedId(), false)
local velolimitada = GetEntitySpeed(coche)
if not limitador then
limitador = true
SetEntityMaxSpeed(coche, velolimitada)
elseif limitador then
limitador = false
SetEntityMaxSpeed(coche, -100.0)
end
end
end
end)