I made a leaderboard that is supposed to save the player's data but this error keeps popping out and yes I checked the little box to enable API Services.
Output Error: "ServerScriptService.Leaderboard:17: attempt to index global 'data' (a nil value)"
local dataStoreService = game:GetService("DataStoreService") local dataStore = dataStoreService:GetDataStore("Currency") game.Players.PlayerAdded:Connect(function(player) local leaderboard = Instance.new("Folder",player) leaderboard.Name = "Leaderboard" local cash = Instance.new("IntValue",leaderboard) cash.Name = "Cash" cash.Value = 10 local recieved,failed = pcall(function() local data = dataStore:GetAsync("User-"..player.UserId) end) if recieved then cash.Value = data[1] print("Data was received") else print("Data was not received") end while true do wait(30) dataStore:GetAsync("User-"..player.UserId{cash.Value}) end end) game.Players.PlayerRemoving:Connect(function(player) local leaderboard = player.Leaderboard local cash = leaderboard.Cash local saved,failed = pcall(function() dataStore:SetAsync("User-"..player.UserId{cash.Value}) end) if saved then print("Data was saved") else print("Data was not saved") end end)
Some assistance would be helpful if anyone knows how to fix this kind of problems.
Oh I see how it's not working, Line 24 should be "SetAsync" not "GetAsync"