Chance of something happening

I’m sorry if this isn’t the wrong section or if I’m blind but I did search around.

Basically what I’m trying to do is during a code block I wanted to create a chance of cops spawning.

Use math.random and base your results on that. So, if you want cops to spawn 60% of the time, you could do math.random(1,100), which generates a random number between 1 and 100. From there, you can use a simple if statement: if math.random(1,100) <= 40 then … Spawn Cops. Or something similar.

Okay… I’m a bit lost here sorry, how would I turn that math.random into doing that?

I was trying do to it like

local policelow = math.random (0,3)

RegisterNetEvent(‘alsek:policelow’)
AddEventHandler(‘alsek:policelow’, function()
SetPlayerWantedLevel(PlayerId(), policelow, false)
end)

local policeChance = math.random(0, 100)

RegisterNetEvent(‘alsek:policelow’)
AddEventHandler(‘alsek:policelow’, function()
  if policeChance > 60 then
    SetPlayerWantedLevel(PlayerId(), 5, false)
  end
end)
1 Like