I am trying to make game like clicking simulator. i made leaderstats, clicks and more but i can't make a saving leaderstats. i tried many of scripts but nothing worked. also one script worked in the roblox studio but when i was published the game and test it doesn't worked. here is that script:
game.Players.PlayerRemoving:connect(function(player) local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats") local statstorage = player:FindFirstChild("leaderstats"):GetChildren() for i = 1, #statstorage do datastore:SetAsync(statstorage[i].Name, statstorage[i].Value) print("saved data number "..i) end print("Stats successfully saved") end)
game.Players.PlayerAdded:connect(function(player) local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats") player:WaitForChild("leaderstats") wait(1) local stats = player:FindFirstChild("leaderstats"):GetChildren() for i = 1, #stats do stats[i].Value = datastore:GetAsync(stats[i].Name) print("stat numba "..i.." has been found") end end)
The script showed no error, but in game its not working!
When I am entering game and checking console there is what it writes:
04:02:20 -- serverscriptservice.stats:20: attempt to index nil with 'value'
stack begin
script 'serverscriptservice.stats', line 20
stack end