So i have made a datastore script that dosent work and when i start the game it says in the output that the LocalPlayer is a Nill value.
Script:
``local Datastore = game:GetService("DataStoreService") local DS1 = Datastore:GetDataStore("Statistics_of_PLR") local Cash = game.Players.LocalPlayer.leaderstats.Cash
game.Players.PlayerAdded:Connect(function(player) Cash.Value = DS1:GetAsync(player.UserId) or 0 DS1:GetAsync(player.UserId.Cash.Value)
Cash.Changed:Connect(function()
print("Saving Data.....")
DS1:SetAsync(player.UserId, Cash.Value)
end)
end)
game.Players.PlayerRemoving:Connect(function(player) DS1:SetAsync(player.UserId, player.leaderstats.Cash.Value) end)

3 comments
LocalPlayer is only available locally.
ok thanks but how can i make this script work without using LocalPlayer?
On PlayerAdded a player is passed into the arguments. Maybe you can grab that player instance's cash value instead?