Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with leaderstats?

The problem is, the leaderstats/Leaderboard does not come up.

local GVs=game.Workspace.GameValues

local DataStore=game:GetService("DataStoreService"):GetDataStore("LavaRise")
local Started=false

game.Players.PlayerAdded:connect(function(Plr)
	repeat wait() until Plr.Character
	Plr.NameDisplayDistance=0
	Plr.HealthDisplayDistance=0
	local AFKValue=Instance.new("BoolValue",Plr)
	AFKValue.Name="Afk"
	local stats=Instance.new("IntValue",Plr)
	stats.Name="leaderstats"
	local Level=Instance.new("NumberValue",stats)
	Level.Name="Level"
	local Wins=Instance.new("NumberValue",stats)
	Wins.Name="Wins"
	local Coins=Instance.new("NumberValue",stats)
	Coins.Name="Coins"
	local Key="Lava Rise Leaderstats - " ..Plr.userId
	local StatsTable=DataStore:GetAsync(Key)
	if not StatsTable then
		StatsTable={0,0,0} --{Level,Wins,Coins}
		DataStore:SetAsync(Key,StatsTable)
	else
		Level.Value=StatsTable[1]
		Wins.Value=StatsTable[2]
		Coins.Value=StatsTable[3]
	end
	if Started==false then
		GVs.LobbyTimer.Value=GVs.LobbyTimer.Time.Value
		GVs.LobbyTimer.CountingDown.Value=true
		Started=true
	end
end)

game.Players.PlayerRemoving:connect(function(Plr)
	local Key="Lava Rise Leaderstats - "..Plr.userId
	local StatsTable={Plr.leaderstats.Level.Value,Plr.leaderstats.Wins.Value,Plr.leaderstats.Coins.Value}
	DataStore:SetAsync(Key,StatsTable)
end)

1 comment

0

Errors? There seems to be nothing wrong with your code.

1 answer

✓ Accepted answer

Set the parent of leaderstats last, after adding other values such as Level, Wins, and Coins.

From line 12 to line 19:

    local stats=Instance.new("IntValue")
    stats.Name="leaderstats"
    local Level=Instance.new("NumberValue",stats)
    Level.Name="Level"
    local Wins=Instance.new("NumberValue",stats)
    Wins.Name="Wins"
    local Coins=Instance.new("NumberValue",stats)
    Coins.Name="Coins"
    stats.Parent = Plr -- set the parent of leaderstats last.

This discussion is preserved as it was. New answers, comments, and votes are closed.