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

Player must press TextButton twice for actions to execute?

When player presses the button, a random item from the table and then executes some actions. The problem occurs when the player presses the button, they must press it twice for the actions to execute.

buyButton = script.Parent
funds = script.Parent.Parent.Parent.Funds
local Skins =
{633409829,
633412461,
}

buyButton.MouseButton1Click:connect(function()
	local x = Skins[math.random(1,#Skins)]
	if x == 633409829 and funds.Value > 24 then
		buyButton.Parent.Cancel.Visible = false
		buyButton.Parent.TextLabel.Text = "Processing"
		buyButton.Parent.TextLabel.Text = "Blossom Skin"
		script.Parent.Parent.Image.Image = "rbxassetid://633409829"
		script.Parent.Parent.Parent.Funds.Value = script.Parent.Parent.Parent.Funds.Value - 25
		script.Parent.Text = "Accept"
	end
	if x == 633412461 and funds.Value > 25 then
		buyButton.Parent.Cancel.Visible = false
		buyButton.Parent.TextLabel.Text = "Processing"
		buyButton.Parent.TextLabel.Text = "Desert Camo"
		script.Parent.Parent.Image.Image = "rbxassetid://633412461"
		script.Parent.Parent.Parent.Funds.Value = script.Parent.Parent.Parent.Funds.Value - 25
		script.Parent.Text = "Accept"
	end
end)

1 answer

✓ Accepted answer

The only reason you'd need to do it twice is if you do not have more than 25 of your currency, which then fails the 2nd conditional statement. If by chance I had exactly 25 but got 633412461 as my number, I'd have to try my luck again. I recommend putting >= instead of just >. Doing that is saying greater than or equal to, which still meets the requirement of 24 or 25 funds.

Just a side note, change line 15 to 24 instead of 25. Ya know, since I don't want to run into the negatives.

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