I am trying to make a StatsUi that stores your stats for example once you level up the text label will update and show the correct number. When I try testing it nothing happens.
My script:
local Player = game:GetService("Players").LocalPlayer
local StatsMain = script.Parent.StatsMain
local PlayerLevelValue = script.Parent.StatsMain.PlayerLevelValue
local PlayerGoldValue = script.Parent.StatsMain.PlayerGoldValue
local PlayerXPValue = script.Parent.StatsMain.PlayerXPValue
local leaderstats = Player:WaitForChild("leaderstats")
local Level = leaderstats:WaitForChild("Level")
local XP = leaderstats:WaitForChild("XP")
local Gold = leaderstats:WaitForChild("Gold")
PlayerLevelValue.Text = Player.leaderstats.Level.Value
PlayerXPValue.Text = Player.leaderstats.Gold.Value
PlayerGoldValue.Text = Player.leaderstats.Gold.Value
This script isn’t working because it’s only changing the stat values when the script first initiates. You need to have some way to tell the script when to change the values. If the levels/gold/XP are calculated on the server then you could use a RemoteEvent. You can then fire the RemoteEvent when the player gains levels up or gains gold/experience and detect it in this script.
The best way to probably do this, like @3Ogre is by using the Changed event, it’s actually pretty simple to do as it can detect whenever the Value changes whether it be client/server side