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

Leaderstats not showing up?

My leaderstats script doesnt seem to work. I've changed it several times, but no matter what I do, it won't work. If anyone can help me here it is:

local nshow = {"attack","strength","defense","fishing","smithing","fletching","cooking",
"woodcutting","crafting","theiving","prayer","farming"} --Different non-showing skills

--Load Data
game.Players.PlayerAdded:connect(function(player)
	player:WaitForDataReady()
	--Leaderstats
	leaderstats.Parent = game.Players:FindFirstChild(player)
    leaderstats.Name = "leaderstats"
	Level = Instance.new("IntValue")
	Level.Parent = leaderstats
	Gold = Instance.new("IntValue")
	Gold.Parent = leaderstats
	Skill = Instance.new("IntValue")
	Skill.Parent = leaderstats
	
	Gold.Name = "Gold"	
	Level.Name = "Gold"
	Skill.Name = "Skill"
	
	if not pcall(function()	Skill.Value = player:LoadNumber("Skill") end) then
   	Skill.Value = 0
	end
	if not pcall(function()	Gold.Value = player:LoadNumber("Gold") end) then
   	Gold.Value = 0
	end
	if not pcall(function()	Level.Value = player:LoadNumber("Level") end) then
   	Level.Value = 1
	end


	--stats
	local stats = Instance.new("Configuration", player)
    stats.Name = "stats"
    for _, stat in pairs(nshow) do
        stata = Instance.new("IntConstrainedValue", stats)
		stata.Name = stat
		stata.MinValue = 1
		stata.MaxValue = 99
		if not pcall(function()	stata.Value = player:LoadNumber(stat.Name) end) then
   		stata.Value = 0
		end
		Instance.new("IntValue",stata).Name = "xp"
		if not pcall(function()	stat.Value = player:LoadNumber(stat.Name.."xp") end) then
   		stat.Value = 0
		end
		Instance.new("IntValue",stata).Name = "nxp"


    end
end)

--Save Data
game.Players.PlayerRemoving:connect(function(player)
    player:WaitForDataReady()
	
	for i,e in pairs(nshow) do
		player:SaveNumber(e.Name,player.stats:FindFirstChild(e).Value)		
		player:SaveNumber(e.Name.."xp",player.stats:FindFirstChild(e).xp.Value)
	end
	
	player:SaveNumber("Skill",Skill.Value)
 	player:SaveNumber("Gold",Gold.Value)
    player:SaveNumber("Level",Level.Value)
end)

6 comments

0

Can you be more specific on what isn't working?

0

I really can't. I have run it several times but it does not error, and it doesn't give the leaderstats to the player. Sorry I can't give more info.

0

Are you only testing this in play solo? In solo, the player is made before playeradded fires.

0

Perhaps through some print lines here and there, to see how far it goes until it crashes?

0

I am testing in server. I'll try the print thing later. a little busy right now...

1

You never defined "leaderstats"

1 answer

✓ Accepted answer
    player:WaitForDataReady()
    --Leaderstats
    leaderstats = Instance.new("IntValue", player)
    leaderstats.Name = "leaderstats"

Instance's 'new' method takes a second parameters, which is what you want to set the parent of what you just created to.

Also, 'player' points to the actual Player object; it isn't a string value.

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