Why won't this datastore work?
Okay. In my game, i use datastores to fill out the values on the leaderboard. I am using an edited version of the Roblox U "Mad Bloxxer" scripts. (No, its not another murder game. I think we've all had enough of those)
First off, here's where I first set up my datastores.
01 | function playeradded(player) |
03 | local mydata = datastore:GetAsync(player.userId) or { } |
04 | mydata.wins = mydata.wins or 0 |
05 | mydata.BC = mydata.BC or 0 |
06 | mydata.hyperlaser = mydata.hyperlaser or 0 |
08 | playerdata [ player.userId ] = mydata |
11 | local leaderstats = Instance.new( "Model" ) |
12 | leaderstats.Name = "leaderstats" |
13 | leaderstats.Parent = player |
16 | local wins = Instance.new( "IntValue" ) |
18 | wins.Value = mydata.wins |
19 | wins.Parent = leaderstats |
21 | local hyperlaser = Instance.new( "IntValue" ) |
22 | hyperlaser.Name = "Hyperlaser" |
23 | hyperlaser.Value = mydata.hyperlaser |
24 | hyperlaser.Parent = player |
26 | local BC = Instance.new( "IntValue" ) |
27 | BC.Name = "BlitzCreditz" |
29 | BC.Parent = leaderstats |
31 | player:WaitForDataReady() |
33 | local stats 2 = player:FindFirstChild( "leaderstats" ):GetChildren() |
35 | stats 2 [ i ] .Value = datastore:GetAsync(stats 2 [ i ] .Name) or 0 |
40 | game.Players.PlayerAdded:connect(playeradded) |
41 | for _, player in pairs (game.Players:GetPlayers()) do |
Here is where I award a win to the player if that player won the game (they won the game if they still have 'MatchTag')
01 | function awardwin(players) |
02 | if type (players) = = type ( { } ) then |
04 | for i = 1 , #players do |
05 | if players [ i ] :FindFirstChild( "MatchTag" ) then |
06 | if players [ i ] :FindFirstChild( "leaderstats" ) then |
07 | if players [ i ] .leaderstats:FindFirstChild( "Wins" ) then |
08 | local stat = players [ i ] .leaderstats.Wins |
09 | stat.Value = stat.Value + 1 |
10 | local newstat = players [ i ] .leaderstats:FindFirstChild( "Wins" ) |
11 | local key = "User_" .. players [ i ] .userId |
12 | datastore:SetAsync(key, function (oldvalue) |
13 | local newvalue = oldvalue or 0 |
14 | newvalue = newvalue + 1 |
Heres my variables...
02 | local intermissiontimer = 5 |
04 | local datastore = game:GetService( "DataStoreService" ):GetDataStore( "playerdata" ) |
05 | local serverstorage = game:GetService( "ServerStorage" ) |
06 | local replicatedstorage = game:GetService( "ReplicatedStorage" ) |
07 | local debris = game:GetService( "Debris" ) |
08 | local maps = serverstorage:WaitForChild( "Maps" ) |
09 | local mapholder = game.Workspace:WaitForChild( "MapHolder" ) |
10 | local gear = serverstorage:WaitForChild( "Gear" ) |
11 | local statustag = replicatedstorage:WaitForChild( "Status" ) |
12 | local timertag = replicatedstorage:WaitForChild( "TimerTag" ) |
13 | local Winner = replicatedstorage:WaitForChild( "Winner" ) |
14 | local resulttag = replicatedstorage:WaitForChild( "result" ) |
15 | local event = replicatedstorage:WaitForChild( "RemoteEvent" ) |
Finally, here's where its supposed to save the data when the player leaves
01 | game.Players.PlayerRemoving:connect( function (player) |
02 | player:WaitForDataReady() |
04 | local stats = player:FindFirstChild( "leaderstats" ):GetChildren() |
08 | datastore:SetAsync(stats [ i ] .Name, stats [ i ] .Value) |
Thanks for the help! Please just give me an edited script, not some vague answer with an example. Not that I want to be picky, but I am a very novice scripter, and it's very hard to learn from something so vague. If I wanted vague answers, I'd be using the Wiki ;)