Help with leaderstats issue

note: im new to posting so i apologize for mistakes

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    whenever i kill the zombies i should get the kills and points
  2. What is the issue? Include screenshots / videos if possible!
    i cant give kills and points due to a error i cant figure out

yesasd

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i couldnt find solutions to my error

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

game.Players.PlayerAdded:Connect(function(player)
	if script.Parent.Zombie.Health >= 0 then
		local leaderstats=game.Players:FindFirstChild("leaderstats")
		leaderstats.Kills.Value += 1
		leaderstats.Points.Value += 2
	end
--this is server script btw
end)```
2 Likes

You have to actually make a leaderstats folder yourself. If you have and it’s being created by another routine, use :WaitForChild(“leaderstats”) instead of :FindFirstChild(“leaderstats”).

Here is a tutorial on how to create your own leaderstats!

im still having issues. i already created a leaderboard
morerrors

Did you name it “leaderstats”? Not the variable, but the actual instance?

Oh. You have to get the leaderstat of the specific PLAYER, not the Players service. Do the following instead.

local leaderstats = player:FindFirstChild("leaderstats")

it still doesnt work. may i need to rewrite the entire script?

screenshots:
morerrorsss

note: it worked the first time. however i play tested again and it broke

Try this instead.

local leaderstats = player:WaitForChild("leaderstats")

ok so the thing is whenever i play tested it gave me the points and kills, however whenever i killed the zombies it didnt give me the points and kills.

@xendatro

it did the same thing as before

Can you show the script you are currently using?

i put the code on the post so u can see

Can you show the updated script?

game.Players.PlayerAdded:Connect(function(player)
	if script.Parent.Zombie.Health >= 0 then
		local leaderstats = player:WaitForChild("leaderstats")
		leaderstats.Kills.Value += 1
		leaderstats.Points.Value += 2
	end
end)

Maybe try this:

game.Players.PlayerAdded:Connect(function(player)
	if script.Parent.Zombie.Health >= 0 then
		local leaderstats = player:WaitForChild("leaderstats")
		leaderstats:WaitForChild("Kills").Value += 1
		leaderstats:WaitForChild("Points").Value += 2
	end
end)

i tried its same result

characters

Are your leaderstats properly being created?

When you load in, check under your Player object and see if the leaderstats folder is actually there.

it is there
morerrororsss

it randomly gave me points and kills when i tested

I just noticed that in the error message you showed in the original post, you’re trying to find the leaderstats within “NoobClone”. I assume this is a mob you’re killing which will award you the points?

yes thats what i was doing

chars

no i wasnt actually trying to give players the points whenever they kill the mobs.
sorry for confusion

i cant delete my previous reply so