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)
You can only 'SetAsync' tables containing information. SetAsync(player.UserId, {Cash.Value}) is what you are looking for.
-- Save local Data = {Cash.Value} DataStorage:SetAsync(plr.UserId, Data)
-- Load local Data = DataStorage:GetAsync(plr.UserId) if Data then Cash.Value = Data[1] else DataStorage:SetAsync(plr.UserId, {0}) end