Saving Script - Fails to save?
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 :
01 | function saveScore(player, score) |
02 | player:SaveNumber( "Gold" , score) |
05 | function saveLevel(player, score 2 ) |
06 | player:SaveNumber( "Lvl" , score 2 ) |
10 | function loadScore(player, killCounter) |
11 | local score = player:LoadNumber( "Gold" ) |
14 | killCounter.Value = score |
16 | print ( "Nothing to load/score was 0" ) |
21 | function loadLevel(player, killCounter 2 ) |
22 | local score 2 = player:LoadNumber( "Lvl" ) |
25 | killCounter 2. Value = score 2 |
27 | print ( "Nothing to load/score2 was 0" ) |
31 | function onPlayerEntered(newPlayer) |
33 | local stats = newPlayer:findFirstChild( "leaderstats" ) |
35 | if (stats ~ = nil ) then |
37 | local clicks 2 = stats:findFirstChild( "Lvl" ) |
39 | local clicks = stats:findFirstChild( "Gold" ) |
46 | newPlayer:WaitForDataReady() |
47 | loadScore(newPlayer, clicks) |
48 | loadLevel(newPlayer, clicks 2 ) |
53 | function onPlayerRemoving(player) |
54 | print ( "Attempting to save score for " .. player.Name) |
55 | local stats = player:FindFirstChild( "leaderstats" ) |
56 | if (stats ~ = nil ) then |
57 | local clicks = stats:FindFirstChild( "Gold" ) |
58 | local clicks 2 = stats:FindFirstChild( "Lvl" ) |
59 | if (clicks ~ = nil ) then |
60 | saveScore(player, clicks.Value) |
62 | if (clicks 2 ~ = nil ) then |
63 | saveLevel(player, clicks 2. Value) |
68 | game.Players.PlayerAdded:connect(onPlayerEntered) |
69 | game.Players.PlayerRemoving:connect(onPlayerRemoving) |
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.