How to prevent spam key?

if someone is in the dealership they can spam enter and buy a vehicle like 10 times before the initial one spawns, can I make it so it waits while enter key pressed to purchase a car?

Did you use IsControlJustReleased

if boughtcar == false then
    if IsControlJustReleased(1,57) then
      boughtcar = true
      TriggerEvent("spawncar")
   end
end

That doesn’t work 100% of the time. You need to use a global to lock the event/function then unlock at the end. Like the hostlock spawnlock.

yeah global false / true fixed it

Yup. Best bet is check the system resources and see how they do stuff. I noticed that in the spawnmanger code. Before the function / event put a lock variable. If locked return at the top. That’s how spawnPlayer works.

1 Like

This might be a big in the Lua implementation.

oldIsControlJustReleased = IsControlJustReleased

IsControlJustReleased = function(...)

    if oldIsControlJustReleased(...) then

        if not Timer then

            Timer = true

            return true

        end

        return false

    end

end

CreateThread(function()

    while true do

        if Timer then

            Wait(1000)

            Timer = false

        end

        Wait(3)

    end

end)

Use this for delay after an control, adjust wait in the thread of tick duration