How can i make a ui change color when you get a certain leaderstat value

i want to make a ui that tracks how many collectibles the player has i have a leaderstat that tracks that but i want a ui to do it
it would bassicly have a greyed out image of the collectible and when you get the collectible it would make it the normal image

so bassicly i dont know how to code but it would be somehting like this

if game.player.Keys.Value = 1 then
game.startergui.collectibles.key.backroundcolor = 0,0,0

btw the leaderstat is called Keys
the screengui is called collectibles and the imagelabel is called key
i would have this script for each different key

Who will be able to see the colour change? Everyone in the server or only the player who has the value?

its a single player game so it doesnt matter

Something like this may work

local Player = game:GetService("Players").LocalPlayer
local Keys = Player:WaitForChild("leaderstats"):WaitForChild("Keys")

local function Reload()
	if Keys.Value == 1 then
		Player.PlayerGui:WaitForChild("Collectibles"):WaitForChild("Key").BackroundColor3 = Color3.fromRGB(0, 0, 0)
	end
end

Keys:GetPropertyChangedSignal("Value"):Connect(Reload)
Reload()

ill try this when i can

1 Like

oh i see

this will work for you hopefully, assuming you have leaderstats set up correctly

local script inside StarterCharacterScripts should work

local player = game.Players.LocalPlayer
local Keys = player:WaitForChild("Keys")

local function Change()
if Keys.Value == 2 then -- change 2 to the number of keys you want it to change the colour for
player.PlayerGui:WaitForChild("Collectibles"):WaitForChild("Key").BackgroundColor = Color3.fromRGB(0,0,0) -- click on the numbers in the script and it will let you change the colour via a palette
 end
end

Keys:GetPropertyChangedSignal("Value"):Connect(Change)
Change()
2 Likes

ok ill try this

1 Like

sry this took so long i had to make the ui lol
it doesnt seem to work tho

Where is your Keys value?
can you screenshot explorer showing where it is and if it’s in a folder

1 Like

i use datastore 2 i think
image

heres the ui
image

its supposed to be a profile thing with like the players health and how many coins they have so there keys under the health bar
image

do you clone the leaderstats folder to the player?

1 Like

yes im pretty sure i do

right

in that case

regular script in serverscriptservice

game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Player:WaitForChild("leaderstats")
local keys = leaderstats:WaitForChild("Keys")

keys.Changed:Connect(function()
 if keys.Value == 2 then -- change 2 to the number of keys you want to change the colour at
 -- change colour
  end)
end)

what is the name of the gui you’re trying to change the colour of?
once you tell me i’ll script the part that changes the colour i just dont know what is supposed to change colour

sry i was eating lunch but the name of the ui’s i want to change are the keys
so there would be a different script for key1 2 and 3 and they would have different values

so…

each key will be a different colour?

no so bassicly they all start black and once you collect the first key then the first one will change color i can do the colors you dont have to but ye bassicly each one changes color when you collect a collectible so the first one when you get the first collectble second when you get the second collectible etc

ohhh
i think i understand now

are the keys just parts in workspace you touch to collect?

ye so i have parts in workspace in each level(there in a folder for level1 2 etc)
and when you touch them they increase your leaderstat by 1

just put a script in each key

it will just change the colour of the image

should do what you want it to
if you need help scripting it just reply and ill script it

1 Like

put the script that you posted above?