Hello, im new to scripting and this is my first game im trying to make...
what im trying to achieve is when the player doesn't have enough money, the button stays red and if the player have enough money, the button turns green. FYI im making a tycoon game.
local tycoon = script.Parent.Parent.Parent.Parent local owner = tycoon.TycoonOwner.Value local button = script.Parent.BuyButon local function CanBuy(player) local pStats = player:WaitForChild("leaderstats") local money = pStats:FindFirstChild("Money") if player then if owner.Name == player.Name then if money.Value >= script.Parent.Cost.Value then button.BrickColor = BrickColor.new("Bright green") else button.BrickColor = BrickColor.new("Bright red") end end end end while true do CanBuy() wait(0.5) end
Player is not defined when firing function
local tycoon = script.Parent.Parent.Parent.Parent local owner = tycoon.TycoonOwner.Value local button = script.Parent.BuyButon local player = game:GetService("Players").LocalPlayer -- define player at the beginning local function CanBuy() local pStats = player:WaitForChild("leaderstats") local money = pStats:FindFirstChild("Money") if player then if owner.Name == player.Name then if money.Value >= script.Parent.Cost.Value then button.BrickColor = BrickColor.new("Bright green") else button.BrickColor = BrickColor.new("Bright red") end end end end while true do CanBuy() wait(0.5) end