How can I create a RNG System which increases the chance of an successful shot and resets the chance afterwards?

Hello There!

As the title says, I’m making a weapon based off a certain battler in The Battle Bricks, that being Gamble Battler. In the game, he has a 1/6 chance of either firing a powerful shot or failing but each time he fails to fire, he increases the chances of successfully firing and each time he fires, the chances reset.

Now, I know how to make the RNG part with math.random(), although, I don’t know how to make it so that each time you fail, the chances increases. How can I do that exactly?

it’s easy,
local Chance = {Minimum,Max}
–example 1 in 20
local number = math.random(Chance[1],Chance[2]
if number ~= 1 and Chance[2] >= 2 then
print(“unsuccess”)
Chance[2] -= 1
elseif number == 1 and Chance[2] >= 2 then
print(“success”)
end

But how can I reset the chance once the player fires a successful shot?

By setting it to 20 (or whatever number) back.

Chance[2] = 20

Alright, thanks!

sklaklaskslda - Filler

I’ve decided to unsolve your answer as I’ve found a problem, it only decreases the chance by one and sticks to that until I guess the chances reset

(For example, when it fails, it decreases the chance by 1/5 and stays like that until I think the chances reset.)

How is that happening? Can I see your code?

Sure, sorry if it’s sloppy

local Chance = {1,6}
	
	local Number = math.random(Chance[1],Chance[2])
	if Number ~= 1 and Chance[2] >= 2 then
		
		GunHandle.Fail:Play()
		Chance[2] -= 1
		print("CHANCE IS NOW "..Chance[2])
		
		GunHandle.Attachment.ParticleEmitter.Enabled = true
		task.wait(0.2)
		GunHandle.Attachment.ParticleEmitter.Enabled = false
		
	elseif Number == 1 and Chance[2] >= 2 then
		
		GunHandle.Fire:Play()
		GunHandle.Attachment.ParticleEmitter.Enabled = true

		ShakeEvent:FireClient(Plr,0.5)

		local raycast = workspace:Raycast(GunHandle.Position, (MousePOS - GunHandle.Position).Unit * 200)
		local hitbox = raycast.Instance

		if hitbox then
			
			local char = hitbox.Parent
			local Humanoid = char:FindFirstChild("Humanoid")
			if Humanoid and char ~= Plr.Character and Humanoid.Health >= 1 then
				Humanoid:TakeDamage(384)

				if Humanoid.Health <= 1 then
					local BodyVelocity = Instance.new("BodyVelocity",char.PrimaryPart)
					BodyVelocity.MaxForce = Vector3.new(1, 1, 1) * math.huge

					local Dir = (char.PrimaryPart.CFrame.Position - Plr.Character.PrimaryPart.CFrame.Position).Unit
					BodyVelocity.Velocity = (Dir + Vector3.new(0, 3, 0)).Unit * 250
					game:GetService("Debris"):AddItem(BodyVelocity,.025)
				end
				
			end

			task.wait(0.2)
			GunHandle.Attachment.ParticleEmitter.Enabled = false
			Chance[2] = 6
			print("CHANCE RESET BACK TO "..Chance[2])
			
		end
1 Like

It’s supposed to work, Unless there are errors.

I don’t see any errors whatsoever.

Are you making the table everytime it fires? That is the reason maybe.

Oh yeah, I’ll try to remove the table out of the remote event

EDIT: It does work, thanks man

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