I am making a script for a store GUI, upon clicking the buy button I want the script to first check if the player clicking the button is on a certain team, if so then proceed to check if the player has the right amount of money. If not, then do not do anything. However, nothing is happening
Here is my function
local player = game.Players.LocalPlayer
local currency = player:WaitForChild('leaderstats').Coins
local itembutton = script.Parent
local amount = 50
local item = game.ServerStorage.RedPotion
local newitem = item:clone()
itembutton.MouseButton1Click:connect(function()
if player.TeamColor == BrickColor.new("Bright Yellow") and currency.Value >=amount and (not player.Backpack:FindFirstChild('RedPotion') or player.Character:FindFirstChild('RedPotion')) then
newitem.Parent = player.Backpack
currency.Value = currency.Value - amount
itembutton.Text = 'Purchased'
itembutton.TextColor3 = BrickColor.Yellow().Color
wait(0.1)
itembutton.TextColor3 = BrickColor.White().Color
wait(0.1)
itembutton.TextColor3 = BrickColor.Yellow().Color
wait(0.1)
itembutton.TextColor3 = BrickColor.White().Color
else
itembutton.Text = 'Failed to purchase'
itembutton.TextColor3 = BrickColor.Red().Color
wait(0.1)
itembutton.TextColor3 = BrickColor.White().Color
wait(0.1)
itembutton.TextColor3 = BrickColor.Red().Color
wait(0.1)
itembutton.TextColor3 = BrickColor.White().Color
wait(0.1)
itembutton.Text = indextext
end
end)
What am I doing wrong here?

1 comment
"Bright Yellow" on line 2 should be "Bright yellow"