[Solved] Wash loop

Hi, I created a function:

Function in client.lua

Citizen.CreateThread(function() – coma thread
while true do
Citizen.Wait(0)
if vRP.isInComa({}) then
TriggerEvent(“cooldown”)
break
end
end
end)

I want Citizen.Wait (0) to break, but after I run this function it does not work anymore.
To work I have to restart the server / script

2 Likes

Um, this isn’t a function and if you use break in a loop it will stop it. Therefore once it knows you’re in a coma once it will never know again because the loop isn’t running again.

how can I do?

So you want to check if the user is in a coma but you don’t want to constantly trigger the cooldown event right?

2 Likes

Yes :slight_smile:

local TempVar = true
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        if vRP.isInComa({}) and TempVar then
            TempVar = false
            TriggerEvent('cooldown')
        elseif not vRP.isInComa({}) then
            TempVar = true
        end
    end
end)

It works very well, thank you very much. You told me it’s not a function, but what is it? (I’m new in this field)

A function would be defined like this:

function ThisIsAFunction(Parameter1, Parameter2)
    -- Enter your code here
end

You have to manually trigger it like this:

ThisIsAFunction('String', 50)

What you were doing is creating a thread, this runs once when the client loads (If it’s client-side) or when the resource starts (If it’s server-side).

do you think this happens because of the thread?

Which is?

No, a thread was correct.

That’s an issue with another resource, I would ask on the original topic.

Can you use code blocks please.
```lua
Code here
```

ok wait

what? :thinking: I did not understand the question

yes, it’s true :slight_smile: but unfortunately I do not understand what I was wrong about this error

It’s not an error, it’s nothing to do with what he’s asking about. If you read it it says “vrp_hotkeys” which isn’t related to a coma. I already replied about this.

Read the above :slight_smile:

Apologies, I thought you were someone different to the original author of the topic :joy: what you sent should be correct (The code). My bad!

ahha ok :slight_smile: !