Thank you @qq_strike
I didn’t use your method because I realized that I already had another function for showing and hiding the UI so I put the removeprogressbarfunction in the else statement and works great but now I have another problem and I hope that it’s the last one too xD
If I move away with the car, everything breaks and it won’t get repaired and progressBar will disappear as intended to but if I move the car, and return to the spot before the 25 seconds the car is cleaned.
-- Show NUI
local isDisplayable = true
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local ped = GetPlayerPed(-1)
if GetDistanceBetweenCoords(-699.67, -933.01, 18.10, GetEntityCoords(ped)) < 5.0 and IsPedInAnyVehicle(ped, true) then
if isDisplayable then
TriggerEvent("nui:display", true)
end
else
TriggerEvent("nui:display", false)
isDisplayable = true
exports['progressBars']:closeUI()
end
end
end)
-- Carwash
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local ped = GetPlayerPed(-1)
local vehicle = GetVehiclePedIsIn(ped, false)
if IsControlJustPressed(0, 18) and GetDistanceBetweenCoords(-699.67, -933.01, 18.10, GetEntityCoords(ped)) < 5.0 and IsPedSittingInAnyVehicle(ped) then
isDisplayable = false
TriggerEvent("nui:display", false)
exports['progressBars']:startUI(25000, "We're washing your car.")
Citizen.Wait(25000)
if GetDistanceBetweenCoords(-699.67, -933.01, 18.10, GetEntityCoords(ped)) < 5.0 and IsPedSittingInAnyVehicle(ped) then
SetVehicleDirtLevel(vehicle, 0.0)
TriggerEvent('chat:addMessage', {
args = {"We've washed your car."}
})
end
end
if IsControlJustPressed(0, 177) and GetDistanceBetweenCoords(-699.67, -933.01, 18.10, GetEntityCoords(ped)) < 5.0 then
isDisplayable = false
TriggerEvent("nui:display", false)
end
end
end)
I know it’s a disaster, by the way
I think I could use CancelEvent around these lines:
else
TriggerEvent("nui:display", false)
isDisplayable = true
exports['progressBars']:closeUI()
but then I’d have to call the whole carwash thing an event and to be honest I don’t have any idea how
LATE LATE EDIT:
I added CancelEvent() there and now it is all solved. Do you think there could be a problem ?
LATE LATE LATE EDIT:
It didn’t work. I am stupid.