|
| 19 Jul 2016 12:46 PM |
I scripted this: local ds = game:GetService("DataStoreService") local ds1 = ds:GetDataStore("Lights")
game.Players.PlayerAdded:connect(function(plr) local folder = Instance.new("Folder") folder.Name = "FlashlightFolder" folder.Parent = plr local item1 = Instance.new("IntValue") item1.Parent = folder item1.Name = "RedLight" item1.Value = ds1:UpdateAsync(plr.UserId) or 0 ds1:UpdateAsync(plr.UserId, item1.Value) local item2 = Instance.new("IntValue") item2.Name = "BlueLight" item2.Parent = folder item2.Value = ds1:UpdateAsync(plr.UserId) or 0 ds1:UpdateAsync(plr.UserId, item2.Value) local item3 = Instance.new("IntValue") item3.Name = "GreenLight" item3.Parent = folder item3.Value = ds1:UpdateAsync(plr.UserId) or 0 ds1:UpdateAsync(plr.UserId, item3.Value) local item4 = Instance.new("IntValue") item4.Parent = folder item4.Name = "PurpleLight" item4.Value = ds1:UpdateAsync(plr.UserId) or 0 ds1:UpdateAsync(plr.UserId, item4.Value) local item5 = Instance.new("IntValue") item5.Parent = folder item5.Name = "PinkLight" item5.Value = ds1:UpdateAsync(plr.UserId) or 0 ds1:UpdateAsync(plr.UserId, item5.Value) local item6 = Instance.new("IntValue") item6.Parent = folder item6.Name = "YellowLight" item6.Value = ds1:UpdateAsync(plr.UserId) or 0 ds1:UpdateAsync(plr.UserId, item6.Value) local item7 = Instance.new("IntValue") item7.Parent = folder item7.Name = "OrangeLight" item7.Value = ds1:UpdateAsync(plr.UserId) or 0 ds1:UpdateAsync(plr.UserId, item7.Value) local item8 = Instance.new("IntValue") item8.Parent = folder item8.Name = "TurquoiseLight" item8.Value = ds1:UpdateAsync(plr.UserId) or 0 ds1:UpdateAsync(plr.UserId, item8.Value) item1.Changed:connect(function() print("Saving ..") ds1:UpdateAsync(plr.UserId, item1.Value) end) item2.Changed:connect(function() print("Saving ..") ds1:UpdateAsync(plr.UserId, item2.Value) end) item3.Changed:connect(function() print("Saving ..") ds1:UpdateAsync(plr.UserId, item3.Value) end) item4.Changed:connect(function() print("Saving ..") ds1:UpdateAsync(plr.UserId, item4.Value) end) item5.Changed:connect(function() print("Saving ..") ds1:UpdateAsync(plr.UserId, item5.Value) end) item6.Changed:connect(function() print("Saving ..") ds1:UpdateAsync(plr.UserId, item6.Value) end) item7.Changed:connect(function() print("Saving ..") ds1:UpdateAsync(plr.UserId, item7.Value) end) item8.Changed:connect(function() print("Saving..") ds1:UpdateAsync(plr.UserId, item8.Value) end) end)
game.Players.PlayerRemoving:connect(function(plr) print("Saving data") ds1:UpdateAsync(plr.FlashlightFolder.RedLight.Value, plr.FlashlightFolder.BlueLight.Value, plr.FlashlightFolder.GreenLight.Value, plr.FlashlightFolder.YellowLight.Value, plr.FlashlightFolder.PurpleLight.Value, plr.FlashlightFolder.PinkLight.Value,plr.FlashlightFolder.TurquoiseLight.Value) print(plr.Name.." 's data has been saved.") end)
I even used UpdateAsync for this but the error is this: 12:44:22.107 - Argument 2 missing or nil 12:44:22.108 - Script 'ServerScriptService.LightSaver', Line 11 12:44:22.109 - Stack End
Can someone tell me what I did wrong? |
|
|
| Report Abuse |
|
|
gskw
|
  |
| Joined: 05 Jan 2013 |
| Total Posts: 1364 |
|
|
| 19 Jul 2016 12:57 PM |
| I think you meant :GetAsync() on the lines where you say "item1.Value = " and similar. |
|
|
| Report Abuse |
|
|
| |
|
|
| 19 Jul 2016 01:12 PM |
Problems:
Use a for loop Don't save everything to the same key, save a table Don't save that often Use GetAsync to retrieve, you're using UpdateAsync instead, which makes no sense. Use SetAsync to save, you're not supposed to use UpdateAsync in that situation
Quite frankly you have so many problems I think you should go back and read the DataStore tutorial, because nothing you're doing makes sense. |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2016 01:19 PM |
@warspy
I was told to use UpdateAsync because it saves a player's data every 1-2.
I know what I'm doing. |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2016 01:21 PM |
| *saves player data after 1-2 seconds. |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2016 02:51 PM |
'I know what I'm doing.' No you clearly do not
1. You can't save multiple values to the one key, and expect it to work, a key is only associated to a single value, if you need more, save an array.
2. UpdateAsync cannot be used to retrieve a value, it's for updating, not getting, use GetAsync.
3. You shouldn't be saving values everytime they change. That is extremely inefficient. When saving a player's values, it should only be done when they leave.
4. UpdateAsync is used to update a value, you need to pass a function as it's second argument that takes the old value as an argument, if you don't need the old value, you use SetAsync.
5. UpdateAsync can't just 'update a DataStore' with a ton of values when a player leaves, you have to set each value to a single key. Why you don't do that, I don't know, because you use a key while getting values (reread point #1)
I was going to rewrite your script for you, so you could learn from it, but after you being so ignorant to the facts I've changed my mind |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2016 04:26 PM |
"I was going to rewrite your script for you, so you could learn from it, but after you being so ignorant to the facts I've changed my mind"
Okay jeez, no need to get mad at me. |
|
|
| Report Abuse |
|
|