Everytime I use this script in my Gui in game, I get a error saying 'Sorry, CashUpgrade is not a valid member of Frame' When it's inside the Frame and the Property of the 'CashUpgrade' states 'Frame'
Anyone know about this error? I've had this error multiple times and don't understant why.
This is a LocalScript
It say's the error line is Line 09
local bloxyColaId = 1378997337 -- Change this to your gamepass ID
local player = game.Players.LocalPlayer
local frame = script.Parent
frame.ImageButton.MouseButton1Click:connect(function()
game:GetService("MarketplaceService"):PromptPurchase(player, bloxyColaId)
end)
frame.CashUpgrade.MouseButton1Click:connect(function()
if player.leaderstats.Money.Value >= 25000 and player.leaderstats.Upgrade.CashUpgrade.Value == 0 then
player.leaderstats.Money.Value = player.leaderstats.Money.Value - 25000
player.leaderstats.Upgrade.CashUpgrade.Value = 1
frame.CashUpgrade.Cash.Text = 'Level 1 Bought!'
wait(2)
frame.CashUpgrade.Cash.Text = 'Upgrade Cash Amount'
if player.leaderstats.Money.Value >= 95000 and player.leaderstats.Upgrade.CashUpgrade.Value == 1 then
player.leaderstats.Money.Value = player.leaderstats.Money.Value - 95000
player.leaderstats.Upgrade.CashUpgrade.Value = 2
frame.CashUpgrade.Cash.Text = 'Level 2 Bought!'
wait(2)
frame.CashUpgrade.Cash.Text = 'Upgrade Cash Amount'
if player.leaderstats.Money.Value >= 250000 and player.leaderstats.Upgrade.CashUpgrade.Value == 2 then
player.leaderstats.Money.Value = player.leaderstats.Money.Value - 250000
player.leaderstats.Upgrade.CashUpgrade.Value = 3
frame.CashUpgrade.Cash.Text = 'Maxed Cash Bought!'
wait(2)
frame.CashUpgrade.Cash.Text = 'Upgrade Cash Amount'
end
end
end
end)

2 comments
The CashUpgrade isn't a Frame.. It's a ImageButton
It Apparently works when I add the 'WaitForChild' saying the script loads too fast for the game to comprehend that there's a CashUpgrade button inside the Frame.