01 | local PlayerDataStore = require(game.ServerScriptService.PlayerDataStore) |
02 |
03 | Game.Players.PlayerAdded:connect( function (p) |
04 | local saveData = PlayerDataStore:GetSaveData(p) |
05 |
06 | local l = Instance.new( "Model" ) |
07 | l.Name = "leaderstats" |
08 | local wins = Instance.new( "IntValue" , l) |
09 | local creds = Instance.new( "IntValue" , l) |
10 | creds.Name = "Credits" |
11 | wins.Name = "Wins" |
12 |
13 | if saveData:Get( "Currency" ) then |
14 | creds.Value = saveData:Get( "Currency" ) |
15 | else |
The parent of leaderstats should be set as the player. At Line 6:
1 | -- Change: |
2 | local l = Instance.new( "Model" ) |
3 | -- To: |
4 | local l = Instance.new( "Model" , p) |
It doesn't work because it's wrong. This is correct:
01 | local PlayerDataStore = require(game.ServerScriptService.PlayerDataStore) |
02 |
03 | game.Players.PlayerAdded:connect( function (p) |
04 | repeat wait() until p.Character |
05 |
06 | local saveData = PlayerDataStore:GetSaveData(p) |
07 | local l = Instance.new( "IntValue" , p) |
08 | l.Name = "leaderstats" |
09 |
10 | local wins = Instance.new( "IntValue" , l) |
11 | local creds = Instance.new( "IntValue" , l) |
12 | wins.Name = "Wins" |
13 | creds.Name = "Credits" |
14 |
15 | --[[ |
16 | Rest of script goes here |
17 | ]] |
18 |
19 | end ) |
Read this: http://wiki.roblox.com/index.php?title=SaveData_(Method)