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

How can i change the colour of a part if the player have enough money?

I tried to write a code that changes colour of a part if the player have enough money. I changed the code to print players money so i can see if it works. It works if the script is in StarterPlayerScript folder but it doesn't while in the part object. Game includes many parts in diffrent models and i thought that i must copy and paste this script into all parts that i want to change its colur depends on players money. Thanks and sorry for my poor English.

local player = game.Players.LocalPlayer
local playermoney = player:WaitForChild("leaderstats").Money

playermoney.Changed:Connect(function()
	print(playermoney.Value)
end)

4 comments

0

im confused what do you want it to do and what have you already accomplished?

0

You're going to need to explain better, what part are you trying to change the color of?

0

If i put this script into StarterPlayerScript folder it works. But when i put it into a part it doesn't. There is diffrent "Buy Buttons" for each player. I try to change these buttons colour if the player have enough money or not.

0

Ah a tycoon game, ok, I can write up an answer for you.

1 answer

✓ Accepted answer

So in order to do this, you will need all the player's buy buttons grouped into a folder or model, it will just be a lot easier if you do this.

Next you just do what you already did, but include a loop to loop through the buy buttons and change the colors if the player has enough money.

local player = game.Players.LocalPlayer
local playermoney = player:WaitForChild("leaderstats").Money
local buttons = workspace[player.Name .. "BuyButtons"] --a folder named "SteamG0DBuyButtons, just create this in a server script when a player joins the game and put all of the tycoon's buy buttons in it. Do this if you don't already have something storing each person's buy buttons.

playermoney.Changed:Connect(function()
    print(playermoney.Value)
    for i,v in pairs(buttons:GetChildren()) do
        if v.IntValue.Value < playermoney.Value then
            v.Color = Color3.fromRGB(0,0,0)
        end
    end
end)

So i'm going to assume you have a value object in each button determining the cost of the button, and this script would go through those buttons, check the values in the buttons, and change the color of the button if the player has enough money.

1 comment

0

Thanks for idea.

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