I’m trying to make a stage counter for my obby, I have a different part of the script that updates when the value of the leaderstats changes, but it won’t pick up the value when the player joins. Help?
local stageCount = script.Parent
local stage = game.Players.LocalPlayer.leaderstats.stage
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild(“leaderstats”)
stageCount.BottomText.Text = leaderstats.stage.Value
end)
Maybe from your leaderstat script you can fire a remote event when the player joins of the value of the stage because I’m pretty sure you can’t access leaderstats value from local script? Im not sure Im probably wrong its been a while since I used leaderstats
The leaderstats is not guaranteed to exist when the LocalScript runs.
You’ll already be in the game before PlayerAdded gets fired.
You are using the wrong player variable in your example, as you are updating the stage value by the latest player’s stage with this logic.
local Players = game:GetService("Players")
-- get LocalPlayer and wait for data
local LocalPlayer = Players.LocalPlayer
local leaderstats = LocalPlayer:WaitForChild("leaderstats")
local stageData = leaderstats:WaitForChild("stage")
local stageCount = script.Parent
-- function to update stage count gui
local function updateStageCount()
stageCount.BottomText.Text = stageData.Value
end
-- update stage count the first time
updateStageCount()
-- update stage count whenever the stageData changes
stageData.Changed:Connect(updateStageCount)
This all assumes you have a proper leaderstats setup.