|
| 17 Jan 2015 07:01 AM |
I am trying to save/load multiple values for my RPG, the only problem is that none of the values actually save or load. I think it may be because I have too many values. I am not sure how to fix this but here is my code:
data = game:GetService("DataStoreService"):GetDataStore("PlayerStats")
function loadSlot(player,slot) for i,v in pairs(slot:GetChildren()) do v.Value = data:GetAsync(v.Name.."_"..player.uderId) end end
function saveSlot(player,slot) for i,v in pairs(slot:GetChildren()) do v.Changed:connect(function() data:SetAsync(v.Name.."_"..player.userId,v.Value) end) end end
(I have got a 'PlayerAdded' function but that is not the important part)
Thanks |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2015 07:02 AM |
I made a typo, here is the fixed one:
data = game:GetService("DataStoreService"):GetDataStore("PlayerStats")
function loadSlot(player,slot) for i,v in pairs(slot:GetChildren()) do v.Value = data:GetAsync(v.Name.."_"..player.userId) end end
function saveSlot(player,slot) for i,v in pairs(slot:GetChildren()) do v.Changed:connect(function() data:SetAsync(v.Name.."_"..player.userId,v.Value) end) end end |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2015 07:13 AM |
This is the output:
13:12:49.176 - String expected 13:12:49.176 - Script 'Workspace.Legend_of_Arzeus_RPG.PlayerHandling', Line 6 - global loadSlot 13:12:49.177 - Script 'Workspace.Legend_of_Arzeus_RPG.PlayerHandling', Line 43 13:12:49.177 - Stack End |
|
|
| Report Abuse |
|
|
drager980
|
  |
| Joined: 25 May 2009 |
| Total Posts: 13385 |
|
|
| 17 Jan 2015 07:14 AM |
you can only hold 60 + 10*playercount amount of saves a minute, don't make it save everytime a single value changes.
AND THE TIGER GOES ROAR |
|
|
| Report Abuse |
|
|
drager980
|
  |
| Joined: 25 May 2009 |
| Total Posts: 13385 |
|
|
| 17 Jan 2015 07:14 AM |
also we cant understand the output w/o teh entire script.
AND THE TIGER GOES ROAR |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2015 07:17 AM |
Should I change the 'Changed' Event to the 'PlayerRemoving' event?
There is only 10 values inside each slot, but only 1 slot is being used. |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2015 07:18 AM |
This is line 6: v.Value = data:GetAsync(v.Name.."_"..player.userId)
This is line 43: loadSlot(player,slot1) |
|
|
| Report Abuse |
|
|
drager980
|
  |
| Joined: 25 May 2009 |
| Total Posts: 13385 |
|
|
| 17 Jan 2015 07:19 AM |
first of all, paste the entire script. and then ill do the playerremoving part for you
AND THE TIGER GOES ROAR |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2015 07:21 AM |
local module = require(workspace["Legend_of_Arzeus_RPG"].ModuleScript) data = game:GetService("DataStoreService"):GetDataStore("PlayerStats")
function loadSlot(player,slot) for i,v in pairs(slot:GetChildren()) do v.Value = data:GetAsync(v.Name.."_"..player.userId) end end
function saveSlot(player,slot) for i,v in pairs(slot:GetChildren()) do v.Changed:connect(function() data:SetAsync(v.Name.."_"..player.userId,v.Value) end) end end
game.Players.PlayerAdded:connect(function(player) player.CanLoadCharacterAppearance = false player:WaitForDataReady() wait(2) player.CharacterAdded:connect(function(char) local pw = Instance.new("Model",char) pw.Name = "PrimaryWeapon" end) local chars = Instance.new("StringValue",player) chars.Name = "Characters" local slot1 = Instance.new("StringValue",chars) slot1.Name = "Slot1" local slot2 = Instance.new("StringValue",chars) slot2.Name = "Slot2" local slot3 = Instance.new("StringValue",chars) slot3.Name = "Slot3" module.statistics(slot1) module.statistics(slot2) module.statistics(slot3) saveSlot(player,slot1) saveSlot(player,slot2) saveSlot(player,slot3) loadSlot(player,slot1) loadSlot(player,slot2) loadSlot(player,slot3) end) |
|
|
| Report Abuse |
|
|
drager980
|
  |
| Joined: 25 May 2009 |
| Total Posts: 13385 |
|
|
| 17 Jan 2015 07:25 AM |
whats the module function doing?
AND THE TIGER GOES ROAR |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2015 07:26 AM |
| The module function is creating the values to store inside each slot, I put it into a module script to make this script look a bit cleaner |
|
|
| Report Abuse |
|
|
drager980
|
  |
| Joined: 25 May 2009 |
| Total Posts: 13385 |
|
|
| 17 Jan 2015 07:30 AM |
are you sure that the v.Value is the same value type as what you're loading?
AND THE TIGER GOES ROAR |
|
|
| Report Abuse |
|
|
| |
|
drager980
|
  |
| Joined: 25 May 2009 |
| Total Posts: 13385 |
|
|
| 17 Jan 2015 07:42 AM |
unless you have the same value name, this shouldn't really happen, ive fiddled with your script so its like this now: local module = require(workspace["Legend_of_Arzeus_RPG"].ModuleScript) data = game:GetService("DataStoreService"):GetDataStore("PlayerStats")
game.Players.PlayerAdded:connect(function(player) local comp = {} player.CanLoadCharacterAppearance = false wait(2)
function loadSlot(player,slot) for i,v in pairs(slot:GetChildren()) do v.Value = data:GetAsync(v.Name.."_"..player.userId) table.insert(comp,v.Name.."_"..player.userId,v.Value) end end
game.Players.PlayerRemoving:connect(function(player) for i,v in pairs(player.Characters:GetChildren()) do for i,k in pairs(v:GetChildren()) do if k.Value ~= comp[k.Name.."_"..player.userId] then data:SetAsync(k.Name.."_"..player.userId,k.Value) end end end end)
player.CharacterAdded:connect(function(char) local pw = Instance.new("Model",char) pw.Name = "PrimaryWeapon" end)
local chars = Instance.new("StringValue",player) chars.Name = "Characters" local slots = {Instance.new("StringValue",chars),Instance.new("StringValue",chars),Instance.new("StringValue",chars)} for i=1, #slots do slots[i].Name = "Slot".. i module.statistics(slots[i]) --saveSlot(player,slots[i]) (not in use) loadSlot(player,slots[i]) end end)
see if it works (probably not)
AND THE TIGER GOES ROAR |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2015 08:16 AM |
| It doesn't work, I guess I'll have to think of another way around this. Thanks for the help though :) |
|
|
| Report Abuse |
|
|