Hit chance for melee weapons is based on strengh.
Hit chance for ranged weapons and melee weapons with the finesse attribute is dexterity.
Hit chance for spells is based is based on the casting stat ( int for wizards, cha for warlocks, wis for rangers and clerics)
The spells of the fighter and rogue subclasses with spells are also based on int.
Physical attacks and some spells target armor class (AC).
Many spells target a saving throw of an ability. (str, dex, con, int, wis, cha ).
You can right click and check characters and enemies to see their AC and stats.
examples: (I assume low lv chars with a profiency bonus of 2)
Your ranger with 18dex attacks and enemy with AC15 by shooting a longbow+1
4 (dex bonus) + 2 ( profiency ) + 1 (weapon enchantment ) + 1d20 needs to be 15 or higher to hit.
Your bonusses are 7, so you need to roll a 8 or higher to hit the enemy.
If you roll a 1 you always miss, if you roll a 20 you always hit and the damage that is rolled is doubled (only rolled damage doubled, not static bonusses)
Your wizard with 18 int casts grease on a rogue with 14 dex.
Enemy saving throw = 8 + 2 (dex bonus) + 2 (profiency bonus ) = 12
Your spell difficulty class = 4 (int bonus) + 2 (profiency bonus) = 6
6 + 1d20 needs to be at least 12
You need to roll 6 or higher to make the enemy slip.
Very importent are advantage and disadvantage.
Advantage means you roll 2 dice and take the result that is better for you.
Disadvantage means you roll 2 dice and take the worse result.
If you have at least one advantage and one disadvantage at once, it is rolled normally no matter how many advantages or disadvantages there are in total.

Prof. Dr. Dr. Mad S. Tist

World leading expert of artificial stupidity.
Because there are too many people who work on artificial intelligence already