Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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)
0
im confused what do you want it to do and what have you already accomplished? botw_legend 502 — 3y
0
You're going to need to explain better, what part are you trying to change the color of? SteamG00B 1633 — 3y
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. dev_veysi -3 — 3y
0
Ah a tycoon game, ok, I can write up an answer for you. SteamG00B 1633 — 3y

1 answer

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
3 years ago
Edited 3 years ago

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.

0
Thanks for idea. dev_veysi -3 — 3y
Ad

Answer this question