#Why is my stage value not showing up in leaderstats?
1 messages · Page 1 of 1 (latest)
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```
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.
** You are now Level 3! **