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

Saving Script - Fails to save?

Asked by
KordGamer 155
10 years ago

I'm writing a script to save the leaderstats of a player when they leave. There are no errors, yet it still doesn't save for some reason. I have tried re-writing the code and searching google, But I couldn't find anything. Could I have some help with this?

This is my script :

01function saveScore(player, score)
02    player:SaveNumber("Gold", score)
03end
04 
05function saveLevel(player, score2)
06    player:SaveNumber("Lvl", score2)
07end
08 
09 
10function loadScore(player, killCounter)
11    local score = player:LoadNumber("Gold")
12 
13    if score ~= 0 then
14        killCounter.Value = score
15    else
View all 69 lines...

I cannot figure this out. Any help is appreciated, Thank you if you could help me out!

I would just really like to know what I've done wrong.

1
Accept my answer if it helped please! EzraNehemiah_TF2 3552 — 10y
0
What is the error, cause I knew there would be an error. EzraNehemiah_TF2 3552 — 10y

1 answer

Log in to vote
5
Answered by 10 years ago

Use DataStores instead:


DataStores

DataStores is a way to save data, but It's better than Data Persistence. Link

1local data = game:GetService("DataStores")
2local save = data:GetDataStores("test")
3save:GetAsync("Bob") --Load
4save:SetAsync("Bob", 1337) --Save
5--When the datastores isn't saved to anything, when you load it, it returns nil!


Final Product

01local gold = game:GetService("DataStoreService"):GetDataStore("Gold") --Add I did was replace data persistence with datastores.
02local lvl = game:GetService("DataStoreService"):GetDataStore("lvl")
03 
04function saveScore(player, score)
05    gold:SetAsync(player.userId, score)
06end
07 
08function saveLevel(player, score)
09    lvl:SetAsync(player.userId, score)
10end
11 
12 
13function loadScore(player, killCounter)
14    local score = gold:GetAsync(player.userId)
15    if score ~= nil then
View all 65 lines...



Hope it helps!

1
Hi, Yeah, Thanks for your help :D KordGamer 155 — 10y
2
Only problem is that it still doesn't work ;-; KordGamer 155 — 10y
0
"It doesn't work" .. *accepts answer* Goulstem 8144 — 10y
Ad

Answer this question