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

Script assumes yes/no button is clicked?

My script (maybe) assumes that the yes/no button in a Gui in PlayerGui was clicked even before the gui appears. Script:

for i = 1e+18, 1, -1 do
					wait(.5)
					print(i .. " Showing debts..")
					if taxYes.MouseButton1Down or taxNo.MouseButton1Down then
						break
					end
				end
				if taxYes.MouseButton1Down or taxNo.MouseButton1Down then
					wait(2)
					unpaid_tax = unpaid_tax_datastore:GetAsync(player.UserId)
					unpaid_tax_storage = unpaid_tax_datastorage:GetAsync(player.UserId)
					debt = ((0 - plrInDebt.leaderstats.Cash.Value) + unpaid_tax or unpaid_tax_storage)
					
					debtAmount.Text = "$" .. debt
					
				end

I'll edit the question if you have a problem concerning the other scripts which are very long.

1 comment

0

Why do you need to use a for loop? Just use a while loop and put a for loop inside it.

1 answer

Okay so, I put a local script inside of a text button, and pasted this:

if script.Parent.MouseButton1Click then
	print("Clicked.")
end

And, when I ran it, the game printed "Clicked" as soon as I joined if even if I clicked it or not.

To fix this, use:

 script.Parent.MouseButton1Click:Connect(function()
	print("Clicked.")
end

Another thing is, you don't need to do a loop at all.

Here's the final code:

local function Clicked()
	taxYes.MouseButton1Down:Connect(function()
		return true
	end)
	taxNo.MouseButton1Down:Connect(function()
		return true
	end)
end
if Clicked() == true then
	wait(2)
	unpaid_tax = unpaid_tax_datastore:GetAsync(player.UserId)
	unpaid_tax_storage = unpaid_tax_datastorage:GetAsync(player.UserId)
	debt = ((0 - plrInDebt.leaderstats.Cash.Value) + unpaid_tax or unpaid_tax_storage)
	
	debtAmount.Text = "$" .. debt
end

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