Hello i get this Message when run this got i tried some things but i dont get it anybody an idea how to fix it? The green line is the problem
14:08:21.857 - ServerScriptService.CurrencyScript1.1:34: attempt to index field 'LocalPlayer' (a nil value)
local DataStore = game:getService( "DataStoreService")
local Storage = DataStore:GetDataStore( "SaveSystem")
game.Players.PlayerAdded:Connect(function(plr)
local folder =Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = plr
local Kills = Instance.new("IntValue")
Kills.Name = "Kills"
Kills.Value = 0
Kills.Parent = folder
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 100
cash.Parent = folder
local success, result = pcall(function()
Storage:GetAsync(plr.UserId)
end)
if not success then
warn(result)
else
local LoadTable = Storage:GetAsync(plr.UserId)
if LoadTable then
Kills.Value = LoadTable[1]
cash.Value = LoadTable[2]
end
end
end)
-- game.Players.LocalPlayer.PlayersRemoving:Connect(function(plr)
local SaveTable = {plr.leaderstats.Kills.Value.plr.leaderstats.Cash.Value}
Storage:SetAsync(plr.UserId. SaveTble)
end)

2 comments
change plr.leaderstats.Kills.Value to Kills.Value
That won't work, it's outside of the PlayerAdded scope.