Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Script assumes yes/no button is clicked?

Asked by 1 month ago
Edited 1 month ago

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.

0
Why do you need to use a for loop? Just use a while loop and put a for loop inside it. Dovydas1118 1097 — 1mo

1 answer

Log in to vote
0
Answered by
raid6n 2309 Moderation Voter Community Moderator
1 month ago

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
Ad

Answer this question