Why does this script stop after 3 times of it running?

Basically this function repeats it’s self until it gets more than or equal to 17.

local function DealersLogic()
						if DealerDeckValue >= 17 then
							OpenBJUI(NewGui)
							Title.Text = "The dealer has chosen to stand at a value of: "..DealerDeckValue
							task.wait(3)
							
							if DealerDeckValue > DeckValue then
								Title.Text = "The dealer has won the game with a value of "..DealerDeckValue
								
								for i,v in Connections do
									v:Disconnect()
								end

								AlreadyBettingPlayers[player] = nil
								Connections = nil
								task.wait(3)

								NewGui:Destroy()
							elseif DealerDeckValue < DeckValue then
								local EquationAmount = math.floor((Betting * 1.5) + 0.5)
								Title.Text = "You have beat the dealer and won: "..EquationAmount
								InvetorySystem.AddItem(player, "Casino Chips", EquationAmount)

								for i,v in Connections do
									v:Disconnect()
								end

								AlreadyBettingPlayers[player] = nil
								Connections = nil
								task.wait(3)

								NewGui:Destroy()
							else
								Title.Text = "You tied and have received your "..Betting.." casino chips back!"
								InvetorySystem.AddItem(player, "Casino Chips", Betting)

								for i,v in Connections do
									v:Disconnect()
								end

								AlreadyBettingPlayers[player] = nil
								Connections = nil
								task.wait(3)

								NewGui:Destroy()
							end
						else
							AddValue(require(game:GetService("ReplicatedStorage"):WaitForChild("Modules"):WaitForChild("RNG")).Roll(CardOdds), "", 2.5)
							if DeckValue < 17 then
								DealersLogic()
							end
						end
					end

Why does it stop working?

3 Likes

Basically at the end of the function if the value is more than 17 then the dealer will do nothing because you aren’t refreshing the function
Run DealerLogic function again even if the value is more than 17

1 Like

On phone so its difficult to read so may not be right but couldnt you do a for loop like:

  for count = 0,17,increment do
         wait(3)
         -- stuff
  end
1 Like

Make sure to do task.wait instead of wait, for performace purposes!

On phone sorry i would have on pc mb

2 Likes

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