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

How can I fix this leaderstats script?

Basically I am trying to make a leaderboard, but here is what I have for it, the problem is it will not show up onto the leaderboard.

local ds=game:GetService("DataStoreService"):GetDataStore("Stats")
game.Players.PlayerAdded:connect(function(np)
	local ls=Instance.new("BoolValue")
	ls.Name="leaderstats"
	local level=Instance.new("NumberValue")
	level.Name="Level"
	local xp=Instance.new("NumberValue")
	xp.Name="XP"
	xp.Parent=ls
	local kills=Instance.new("NumberValue")
	kills.Name="Kills"
	kills.Parent=ls
	level.Parent=ls
	ls.Parent=np
	kills.Value=0
	level.Value=0
	xp.Value=0
	dsl=ds:GetAsync(tostring(np.userid).."Level")
	if dsl==nil then
		ds:SetAsync(tostring(np.userid).."Level", 0)
	else
		level.Value=ds:GetAsync(tostring(np.Userid).."Level")
	end
	dsxp=ds:GetAsync(tostring(np.userid).."XP")
	if dsxp==nil then
		ds:SetAsync(tostring(np.userid).."XP", 0)
	else
		xp.Value=ds:GetAsync(tostring(userid).."XP")
	end
end)
game.Players.PlayerRemoving:connect(function(lp)
	level=lp.leaderstats.Level
	ds:SetAsync(tostring(lp.userid).."Level", level.Value)
	ds:SetAsync(tostring(lp.userid).."XP", xp.Value)
end)
game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		local humanoid=character:WaitForChild("Humanoid")
		humanoid.Died:connect(function()
			local value=humanoid:FindFirstChild("creator")
				local kp=value.Value
				if kp~=nil then
					kp.leaderstats.Kills.Value=kp.leaderstats.Kills.Value +1
					kp.leaderstats.XP.Value=kp.leaderstats.XP.Value + 10
					local xpn=kp.leaderstats.Level.Value * 100
					if kp.leaderstats.XP.Value >= xpn then
						kp.leaderstats.Level.Value=kp.leaderstats.Level.Value +1
						ds:SetAsync(tostring(kp.userid).."Level", kp.leaderstats.Level.Value)
						ds:SetAsync(tostring(kp.userid).."XP", kp.leaderstats.XP.Value)
				end
			end
		end)
	end)
end)

Thank you in advance.

2 comments

0

What is the problem with it?

0

It will not show up onto the leaderboard.

1 answer

✓ Accepted answer

Not everything the humanoid when they die will be a creator value, so you should've kept the code inside the died event the same (unless you found another error inside of it).

That is all I noticed, if I find anything else I'll edit my answer.

17 comments

0

So I should reset the values when they join the game automatically to 0?

0

Yes

0

Okay I will see if this will work, thank you.

0

Nope I found it, when I name the xp value I forgot to put it in a string.

0

Ahh, I skipped over that. Still, though, the values probably default to 0.

0

I think so, any ways I tested it again, the board showed up, and then when I killed him it didn't count it onto the board, I think it may be the gun but it named the tag value the same thing. Any ideas?

0

I think the event is "Died" instead of "Dead" (of the Humanoid)

0

TY, that is it!

0

Nope, it is still not working.

0

Im going to repost what the script has now.

0

I edited my question with the new script.

0

I also edited my answer.

0

Okay and I start changing this up again.

0

level is parented to leaderstats right after kills.

0

Ahh, I couldn't find it. But the Died part still applies I assume

0

Probably, I saw the other way I had it with the loop in someone elses answer for finding the tag, so I figured I might aswell give it a shot.

0

I got the kills, xp, and level to work, but it only shows up for 1 person(the 1st person to join), the others don't even have 0s in their spots.

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