Attempt to index nil with leaderstats?

I have a serverscript which initiates whenever a boss is defeated, however it is saying attempt to index nil with leaderstats when leaderstats very clearly exists.
The error is in the 1st line this is only a part of the code and that’s where the error occurs.

					local store = game.Players.LocalPlayer:WaitForChild("leaderstats")
					store.EXP.Value = store.EXP.Value + script.Parent.Config.EXP.Value--/RewardDivider
					store.G.Value  = store.G.Value + script.Parent.Config.Gold.Value--/RewardDivider
						---------------	
					if store.LV.Value <=10 then
					if 	store.EXP.Value >=store.LV.Value * store.LV.Value * 100 + 400 then
						store.LV.Value = store.LV.Value + 1
					end
					end
						if store.LV.Value >10 and store.LV.Value <=20 then
					if 	store.EXP.Value >=store.LV.Value * store.LV.Value * 150 + 400 then
						store.LV.Value = store.LV.Value + 1
					end
					end
					if store.LV.Value >20 and store.LV.Value <30  then
					if 	store.EXP.Value >=store.LV.Value * store.LV.Value * 200 + 400 then
						store.LV.Value = store.LV.Value + 1
					end
					end
					if store.LV.Value >=30  then
					if 	store.EXP.Value >=store.LV.Value * store.LV.Value *  store.LV.Value  *10+ 400 then
						store.LV.Value = store.LV.Value + 1
					end
					end
					----------------
					player.leaderstats.EXP.Value = store.EXP.Value
					player.leaderstats.G.Value  = store.G.Value		
					player.leaderstats.LV.Value = store.LV.Value 

Doesn’t make a difference if there’s a waitforchild or not help would be greatly appreciated thank you

The error is saying what you are looking in for leaderstats is nil. This is because you can’t use game.Players.LocalPlayer in a Server Script

How am I supposed to link it to server then?

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player) --== Player is that player

    -- Your code here

end)

But it activates everytime the boss dies so this would work then?

If you know who the player is (e.g. you have the ‘Player’ instance), you can use:

local store = game.Players[Player.Name]:WaitForChild('leaderstats')

Also, please note that if you ever try and change a user’s stats (on leaderstats) on a LocalScript, that won’t replicate to the server.

Let me know if you need anymore help!

No I mean, put your leaderstats into there, it will give each player the leaderstats folder and whatever other values you have

And then that would work with my script?

That should fix your leaderstat issue but is this a local or server script?

serverscript which is inside a boss and when the boss dies it activates

Well if your goal is to update every player that should be updated do something like

local players = game:GetService("Players") -- Player service

players.PlayerAdded:Connect(function(player) 

		local store = player:FindFirstChild("leaderstats") -- Will return nil or true, you do not need :WaitForChild in server scripts

        if store then -- If leaderstats is found

                    store.EXP.Value = store.EXP.Value + script.Parent.Config.EXP.Value--/RewardDivider
					store.G.Value  = store.G.Value + script.Parent.Config.Gold.Value--/RewardDivider
						---------------	
					if store.LV.Value <=10 then
					if 	store.EXP.Value >=store.LV.Value * store.LV.Value * 100 + 400 then
						store.LV.Value = store.LV.Value + 1
					end
					end
						if store.LV.Value >10 and store.LV.Value <=20 then
					if 	store.EXP.Value >=store.LV.Value * store.LV.Value * 150 + 400 then
						store.LV.Value = store.LV.Value + 1
					end
					end
					if store.LV.Value >20 and store.LV.Value <30  then
					if 	store.EXP.Value >=store.LV.Value * store.LV.Value * 200 + 400 then
						store.LV.Value = store.LV.Value + 1
					end
					end
					if store.LV.Value >=30  then
					if 	store.EXP.Value >=store.LV.Value * store.LV.Value *  store.LV.Value  *10+ 400 then
						store.LV.Value = store.LV.Value + 1
					end
					end
					----------------
					player.leaderstats.EXP.Value = store.EXP.Value
					player.leaderstats.G.Value  = store.G.Value		
					player.leaderstats.LV.Value = store.LV.Value 

        else -- If leaderstats isn't found
     
               warn("Leaderstats not found for " .. player.Name .. "!")

        end
end)

I believe that would work, also make sure you create leaderstats

Also you have a lot of ifs. These aren’t good in certain situations and you should use elseif depending on what it does. Because if you check one value and it’s true then change it and check it again, it could return true multiple times causing stuff you don’t want

For example
I want this to check if someone has 10 money or less
If they have less than 10 or = to 10 then I want them to gain money
If they have more I want them to lose money

if money.Value <= 10 then 
   money.Value += 5
end
if money.Value > 10 then
   money.Value -= 10
end

That will add 5 then because it’s now over 10 it will then remove 10
To make it only do one thing I would do

if money.Value <= 10 then -- If met it doesn't run the elseif
   money.Value += 5

elseif money.Value > 10 then
   money.Value -= 10

end

That will give me 5 cash if I have 10 or less and will not remove 10 after
If I have over 10 it will remove 10 and that’s all

Now this doesn’t mean do it for all ifs, I don’t exactly know what you’re doing but if you do have issues with what’s given/taken/changed this could be the issue or you may not have any issues, of course test it first. Hope this helps