#Why is my stage value not showing up in leaderstats?

1 messages · Page 1 of 1 (latest)

sudden socket
#

I have no error message in output and the stages are being saved since they show up in the PlayerData folder.. so why won't it display on the leaderstats?

#

here's the script:

#
local PlayerDataFolder = serverStorage:WaitForChild("PlayerData")
local Spawns = game.Workspace:WaitForChild("Checkpoints")

game.Players.PlayerAdded:Connect(function(player)
    player.RespawnLocation = game.Workspace.Checkpoints["0"]
    
    local playerFolder = Instance.new("Folder")
    playerFolder.Name = player.UserId
    playerFolder.Parent = PlayerDataFolder
    
    local currentStage = Instance.new("IntValue")
    currentStage.Name = "Stage"
    currentStage.Value = 0
    currentStage.Parent = playerFolder
    ------------------------------------------------
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    
    local stageDisplay = Instance.new("IntValue")
    stageDisplay.Name = "Stages"
    stageDisplay.Value = currentStage.Value 
    stageDisplay.Parent = leaderstats
end)

for i, v in pairs(Spawns:GetChildren()) do
        v.Touched:Connect(function(otherpart)
            if otherpart.Parent:FindFirstChild("Humanoid") then
                local player = game.Players:GetPlayerFromCharacter(otherpart.Parent)
                local playerFolder = PlayerDataFolder:FindFirstChild(player.UserId)
                local currentStage = playerFolder:WaitForChild("Stage")
                local spawnStage = tonumber(v.Name)
                if (spawnStage == currentStage.Value + 1) then
                    currentStage.Value = currentStage.Value + 1
                    player.RespawnLocation = v
                end
            end
        end)
    end```
clear elk
#

its because your not updating the value of stageDisplay.Value your only updating currentStage.Value

#

My solution creates main table called playerTbl. When a player joins, I insert their UserId into the table, and assign it a nested subtable. Inside that nested table, I store a key named stageDisplay, whose value is the actual IntValue object named "stageDisplay" in leaderstats.

pastel vesselBOT
#

studio** You are now Level 3! **studio

clear elk
#
if (spawnStage == currentStage.Value + 1) then
      currentStage.Value = spawnStage
      playerTbl[uid]['stageDisplay'].Value = spawnStage
      player.RespawnLocation = spawn
end