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

Why is this script not making a leaderboard in-game?

local PlayerDataStore = require(game.ServerScriptService.PlayerDataStore)

Game.Players.PlayerAdded:connect(function(p)
	local saveData = PlayerDataStore:GetSaveData(p)
	
	local l = Instance.new("Model")
	l.Name = "leaderstats"
	local wins = Instance.new("IntValue", l)
	local creds = Instance.new("IntValue", l)
	creds.Name="Credits"
	wins.Name="Wins"
	
	if saveData:Get("Currency") then
		creds.Value=saveData:Get("Currency")
	else
		saveData:Set("Currency", 0)
		creds.Value=saveData:Get("Currency")
	end
	
	if saveData:Get("Victories") then
		creds.Value=saveData:Get("Victories")
	else
		saveData:Set("Victories", 0)
		creds.Value=saveData:Get("Victories")
	end
	
	wins.Parent=l
	creds.Parent=l
	
	creds.Changed:connect(function(val)		
		saveData:Set("Currency", val)
	end)
end)

2 answers

✓ Accepted answer

The parent of leaderstats should be set as the player. At Line 6:

-- Change: 
local l = Instance.new("Model")
-- To:
local l = Instance.new("Model", p)

1 comment

0

Thanks, stupid mistake XD

It doesn't work because it's wrong. This is correct:

local PlayerDataStore = require(game.ServerScriptService.PlayerDataStore)

game.Players.PlayerAdded:connect(function(p)
	repeat wait() until p.Character

	local saveData = PlayerDataStore:GetSaveData(p)
	local l = Instance.new("IntValue", p)
	l.Name = "leaderstats"

	local wins = Instance.new("IntValue", l)
	local creds = Instance.new("IntValue", l)
	wins.Name = "Wins"
	creds.Name = "Credits"

	--[[
		Rest of script goes here
	]]

end)

Read this: http://wiki.roblox.com/index.php?title=SaveData_(Method)

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