Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Here is a better explanation version of my previous question?

So I have a system were you have money and spend it in a well either you can get winner or loser that is decided on a math.Random() function it all works but the random part it work the first time but after that it starts giving out more number example: First time - 100, Second Time - 45,100,540 and I need only one number here is the script.


local Clicked = false
local TimesBeforeCoolDown = 12
local TimesUsed = 0
local CoolDown = 120

local ShowEmpty = false

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	if(Clicked == false and ShowEmpty == false)then
		if(TimesUsed >= TimesBeforeCoolDown and ShowEmpty == false)then
			plr.PlayerGui.WellScreenEmpty.Enabled = true
			wait(2.5)
			plr.PlayerGui.WellScreenEmpty.Enabled = false
			ShowEmpty = true
			wait(CoolDown)
			TimesUsed = 0
			ShowEmpty = false
		elseif(plr.leaderstats.Coins.Value >= 1 and TimesUsed ~= TimesBeforeCoolDown)then

					plr.PlayerGui.WellWinnerOrLoser.BackroundRound.Winner.Visible = false
					plr.PlayerGui.WellWinnerOrLoser.BackroundRound.Loser.Visible = false
			
					plr.PlayerGui.WellScreen.Enabled = true
			
			--YESBUTTON
			plr.PlayerGui.WellScreen.BackroundRound.Backround.YesButton.MouseButton1Click:Connect(function()
				
				local RNumb = math.random(-1050,1000)
				plr.PlayerGui.WellScreen.Enabled = false
				
				TimesUsed = TimesUsed + 1
				plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value - 1
				print(RNumb)
				plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + RNumb
				
				if(RNumb > 0)then
					plr.PlayerGui.WellWinnerOrLoser.Enabled = true
					plr.PlayerGui.WellWinnerOrLoser.BackroundRound.Winner.Visible = true
					wait(2.5)
					plr.PlayerGui.WellWinnerOrLoser.Enabled = false
					plr.PlayerGui.WellWinnerOrLoser.BackroundRound.Winner.Visible = false
	
				elseif(RNumb < 0)then
					plr.PlayerGui.WellWinnerOrLoser.Enabled = true
					plr.PlayerGui.WellWinnerOrLoser.BackroundRound.Loser.Visible = true
					wait(2.5)
					plr.PlayerGui.WellWinnerOrLoser.Enabled = false
					plr.PlayerGui.WellWinnerOrLoser.BackroundRound.Loser.Visible = false
				end
				
				--NOBUTTON
					plr.PlayerGui.WellScreen.BackroundRound.Backround.NoButton.MouseButton1Click:Connect(function()
					plr.PlayerGui.WellScreen.Enabled = false
				end)
			end)
		else
			plr.PlayerGui.WellScreenPoor.Enabled = true
			wait(2.5)
			plr.PlayerGui.WellScreenPoor.Enabled = false
		end
	elseif(ShowEmpty == true)then
		plr.PlayerGui.WellScreenEmpty.Enabled = true
		wait(2.5)
		plr.PlayerGui.WellScreenEmpty.Enabled = false
	end
end)

4 comments

0

im not going to read that long script, sorry, maybe debug it so we know where the problem is

0

nvm

0

did you click the button 3 times the second time

0

no

1 answer

Run math.random only once and store the returned value in a variable.

This discussion is preserved as it was. New answers, comments, and votes are closed.