Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

i need to make saving leaderstats but nothing worked for me how can i fix it?

Asked by 4 years ago
Edited by JesseSong 4 years ago

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:

Saving the stats:

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)

Loading the stats:


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

Answer this question