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

6 comments
What line is the error at?
Do you have leaderboards setup yet?
in line 07
yes, i set up the leaderboards
my guess: since you are firing the CanBuy function with a while true do, its going to run into an error maybe because it fires before the leaderboard actually loads. Just a guess though
hmm the error is gone, but the script not working