After landing on math.random value the effect stays forever?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Im making a 1 and 15 chance of having the bullet making an explosion

  1. What is the issue? Include screenshots / videos if possible!

After the random value lands on ‘1’ the gun will fire explosive bullets forever, instead of doing it once.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

i tried removing the event, but then got a vector3 error with ‘position’. i tried having a remote event made for the mouse position so i can gather the position for the explosion but i kept running into errors.

		local config = require(assets.Config)
		if config.thunderPaP == true then
			local random = math.random(1, 15)
			print (random)
			if random ==  1 then
				random = 2
				Evt.HitEffect.OnServerEvent:Connect(function(plr,trg,dmg, Position)
				print ("thunder effect")
					script.Parent.Assets.Special.TG:Play()
				local explo = Instance.new("Explosion", workspace)
				explo.Visible = true
				explo.BlastRadius = 100
				explo.BlastPressure = 0
				explo.DestroyJointRadiusPercent = 0
				explo.ExplosionType = Enum.ExplosionType.NoCraters
				explo.Position =  Position
				game.Debris:AddItem(explo, 2)

				explo.Hit:Connect(function(hitpart)
					if hitpart.Name == "Head" and hitpart.Parent:FindFirstChild("Humanoid") then
						local cChr = hitpart.Parent
						local cPlr = game.Players:GetPlayerFromCharacter(cChr)

						local dist = (cChr.HumanoidRootPart.Position).Magnitude
						local MaxZone = config.ExplosionRadius
						local MinZone = MaxZone / 3

						local dmg = math.huge

						if cChr.Name == "Vertition's Soul" then
							--print(cChr)


						else


							if not cPlr or cPlr == plr  then
								local skp_t	= Instance.new("ObjectValue")
								skp_t.Name	= "creator"
								skp_t.Value	= plr
								skp_t.Parent= cChr.Humanoid
								game.Debris:AddItem(skp_t, 1)
								if dist < config.ExplosionRadius / 3 then
									if cChr.Name == "Zombie" then 

										cChr.Humanoid.Health = cChr.Humanoid.Health - dmg


										print "too close"




									else

										print "Player"


									end
								end
							end
						end
					end
				end)

				--Explosion fx


				local effectAtt = Instance.new("Attachment",workspace.Terrain)
				effectAtt.WorldCFrame = CFrame.new(Position)
	
end)
			
			else
	
				dmg = dmg * plr.Character.Variables.DoubleTap.Value
				trg.Parent.Humanoid:TakeDamage(dmg)

				bleed()
			end

		else

			dmg = dmg * plr.Character.Variables.DoubleTap.Value
			trg.Parent.Humanoid:TakeDamage(dmg)
			print (dmg)
			bleed()
		end

bump

text limit

The output may have yelled at you for not making the variable local, try setting random = 2 to local random = 2
If that doesn’t work, i think that when the random number hits 1, you are associating it with 2 where it would keep the value of 2, i’m uncertain, but try to replace random = 2 with
random = math.random(1,15)
hope it helps!

Your config.thunderPap == true – never changes to false
If its true your creating the explosion, but it never changes to false

Your explo.Hit:Connect(function(hitpart) – might need a debounce
A hit part will register the hit many times over without a debounce and wait in place