Help leaderstats not working

my script wont work for some reason does anyone no why?

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local kills = Instance.new("NumberValue", leaderstats)
	kills.Name = "Kills"
	kills.Value = 0
	
	local deaths = Instance.new("NumberValue", leaderstats)
	deaths.Name = "Deaths"
	deaths.Value = 0
	
	player.CharacterAdded:Connect(function(charcter)
		local humanoid = charcter:FindFirstChild("Humanoid")
		
		humanoid.Died:Connect(function(died)
			deaths.Value = deaths.Value + 1
			local tag = humanoid:FindFirstChild("creator")
			local killer = tag.Value
			if tag and killer then
				killer.leaderstats:FindFirstChild("kills".Value = killer.leaderstats:FindFirstChild("kills").Value + 1
			end
		end)
	end)
end)

you forgot to put a ) after “kills”
and “kills” should be “Kills”

do i just put that under

local kills = Instance.new("NumberValue", leaderstats)
	kills.Name = "Kills"
	kills.Value = 0

Protip: when requesting for help, please make sure to specify what you need help on and supply details such as the exact source of error (check your console!). A single sentence asking for help isn’t descriptive enough of the problem and makes it more difficult for others to help you. Be sure to also proofread your script for red underlines or other similar issues.

Regarding the suggestion MediaHQ made, no, look carefully at your script. You forgot a parenthesis near the bottom. Their post is saying that you need to add that closing bracket around kills so that it doesn’t error. It says to fix that mistake, not to add new code.

1 Like

i dont see anythang wrong with my code

killer.leaderstats:FindFirstChild("kills".Value = killer.leaderstats:FindFirstChild("kills").Value + 1

image

Please read the advice carefully and proofread your code carefully as well. The given advice mentioned correcting this to Kills with a capital K and adding the closing bracket before accessing the Value.

2 Likes

i fixed it but there’s still an error

You can hover over red outlines to see what the exact problem in your code is. That being said though it just might not be registering your change or you committed it incorrectly. I copied your code into a blank baseplate and made the exact changes suggested by MediaHQ and no such underline appeared.

To be sure, are you sure you’re following the advice carefully? I’ll repeat again just in case: use the same code you originally had, but add the closing bracket ) beside kills when you use FindFirstChild and change the Kills in the quotes to have capital Ks. Don’t add new code, don’t put it on a new line. You just need to add one character and change the capitalisation of another.

i dont understand i put it all how you said i just put a capital K and it still has a red line

Could you please check what the script editor tells you when you hover over the red line?

thats what i did and its telling me what i already did its telling me to make sure i do (Kills) but i already did

You should be good if you’ve made those changes then. You could try closing and reopening the script to see if the red line still exists, sometimes the script editor has trouble recognising that you’ve already made the changes needed or it could be that you have another issue overlooked.

Another thing you can try is play testing your game to see if your leaderboard script works now. If it doesn’t, please do check the console and check for any errors related to your script.

1 Like

i did fix it it was not recognizing the script thank you so much for the help !

wait where do i need to replace this ?

Sorry, I made a mistake. I didn’t see that you used the second argument of Instance.new to set the leaderstats folder’s parent before I posted it. That part of your code is fine.

alright thank you for telling me i got worried for a sec lol

1 Like

for anyone thats needs help with a leaderstats here you go


game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local kills = Instance.new("NumberValue", leaderstats)
	kills.Name = "Kills"
	kills.Value = 0
	
	local deaths = Instance.new("NumberValue", leaderstats)
	deaths.Name = "Deaths"
	deaths.Value = 0
	
	player.CharacterAdded:Connect(function(charcter)
		local humanoid = charcter:FindFirstChild("Humanoid")
		
		humanoid.Died:Connect(function(died)
			deaths.Value = deaths.Value + 1
			local tag = humanoid:FindFirstChild("creator")
			local killer = tag.Value
			if tag and killer then
				killer.leaderstats:FindFirstChild("Kills").Value += 1
			end
		end)
	end)
end)