How to make Chance system

I am making a game and i’m looking for one of the core mechanics to be crit dmg and i also want crit chance in it, the problem is idk percentages since i am still learning that in algebra 1, i’m probably gonna use a num value and update the value everytime the player wears something that increases crit chance, so im looking how to make the chances match the player’s crit chance value out of 100%

1 Like

You can make a number that is random using

local number = math.random(0, 100)

And then you get the amount of luck that the player has or something and then you check if the luck is higher than the number like this

local number = math.random(0, 100)
local playerluck = --whatever your player luck is
if number <= playerluck then
      --do stuff

of course you have to update the value everytime the crit chance changes for the player.

1 Like

It’s important to know how to use math.random(min, max).

Then you can use the given random value and create a result with it.

1 Like

would this work as well? i made this but im bad in percentages so idk how accurate it was.

		local chance = math.random(Playerluck,100)
		if chance == Playerluck then

It would not work exactly the same because you are not doing it in a full scale of out of 100%. That method only gives a number between the player luck and 100, which means that you can’t exactly do the same thing.

So no, it would not work. The percentage would be way too small no matter what it is, meaning crits would almost never happen.

okay thank u i will use the first response and hopefully my algebra teacher will teach us on percentages

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.