game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local CoinAmount = script.Parent.SideBar.CoinValue.Amount
local GemAmount = script.Parent.SideBar.GemValue.Amount
CoinAmount.Text = leaderstats.Coins.Value
GemAmount.Text = leaderstats.Gems.Value
local function coinchanged()
CoinAmount.Text = leaderstats.Coins.Value
end
local function gemchanged()
GemAmount.Text = leaderstats.Gem.Value
end
leaderstats.Coins.Changed:Connect(coinchanged)
leaderstats.Gems.Changed:Connect(gemchanged)
end)
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local CoinAmount = script.Parent.SideBar.CoinValue.Amount
local GemAmount = script.Parent.SideBar.GemValue.Amount
CoinAmount.Text = leaderstats.Coins.Value
GemAmount.Text = leaderstats.Gems.Value
local function coinchanged()
CoinAmount.Text = leaderstats.Coins.Value
end
local function gemchanged()
GemAmount.Text = leaderstats.Gem.Value
end
leaderstats.Coins.Changed:Connect(coinchanged)
leaderstats.Gems.Changed:Connect(gemchanged)
I’d create references to the individual stats like you have, that way you’re not frequently indexing the leaderstats instance for its “-Value” instances.
local players = game:GetService("Players")
local player = players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local gems = leaderstats:WaitForChild("Gems")
local coins = leaderstats:WaitForChild("Coins")
local frame = script.Parent
local sideBar = frame.SideBar
local gemLabel = sideBar.GemValue
local gemAmount = gemLabel.Amount
local coinLabel = sideBar.CoinValue
local coinAmount = coinLabel.Amount
gemAmount.Text = gems.Value
coinAmount.Text = coins.Value
gems.Changed:Connect(function(newGems)
gemAmount.Text = newGems
end)
coins.Changed:Connect(function(newCoins)
coinAmount.Text = newCoins
end)