Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
|
| 26 Jan 2015 09:20 PM |
This is a DataStore script. It's suppose to save and load IntValues using a table when a user leaves and enters the game. It's always prints "No cards found" even if I have cards when I leave the game.
print("Save script loaded.") ds = game:GetService("DataStoreService"):GetDataStore("CardsSaveV.3") PlayersCards = ds:GetAsync("CardsV.3")
game.Players.PlayerAdded:connect(function(Plr) repeat wait() until Plr.Character if ds:GetAsync(Plr.userId,PlayersCards) ~= nil then for i, v in pairs(PlayersCards) do print("Cards found") local val = game.Lighting.Cards[v.Name]:Clone() val.Parent = game.Players[Plr.Name].Cards end else print("No cards found.") end end)
game.Players.PlayerRemoving:connect(function(Plr) print("Saving Game...") for i,v in pairs(game.Players[Plr].Cards:GetChildren()) do print(v.Name) table.insert(v.Name,PlayersCards) end ds:SetAsync(Plr.userId,PlayersCards) print("Game Saved!") end) |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2015 10:04 PM |
um the problem is on line 9:
print("im not a mexican") |
|
|
| Report Abuse |
|
|
Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
| |
|
Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
| |
|
Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
| |
|
Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
| |
|
Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
| |
|
| |
|
Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
|
| 27 Jan 2015 05:42 PM |
All the into is in the first post, but there is none except for "No cards found." witch is in the script.
There are no errors what so ever. |
|
|
| Report Abuse |
|
|
Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
| |
|
|
| 27 Jan 2015 06:46 PM |
The problem is that your not reading the data from the datastore. you should have some line that goes something like this. PlayersCards = ds:GetAsync(Plr.userId,PlayerCards) it should be on added between line 7 and 8. not sure if that is 100 percent correct but it is a start. |
|
|
| Report Abuse |
|
|
Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
|
| 27 Jan 2015 07:15 PM |
Why is that tho? I have it set already and it should be able to read it in both events.
If I where to set it again wouldn't it not work like it's suppose to due to having two of the same vals or something like that? |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2015 08:10 PM |
no it should work fine for example:
a = 1 print(a)
for i=1, 5 do a = 1 print(a) end
that would print 1 six times.
we are changing the variable to the same value. |
|
|
| Report Abuse |
|
|
Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
|
| 27 Jan 2015 08:19 PM |
Ya, I get that. But I have little to none exp when it comes to DataStore so I'm not to sure what I can and can't do yet. |
|
|
| Report Abuse |
|
|
Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
|
| 27 Jan 2015 08:20 PM |
| So where should this be again, I'm not quite sure... In removing or enter? |
|
|
| Report Abuse |
|
|
|
| 27 Jan 2015 08:43 PM |
print("Save script loaded.") ds = game:GetService("DataStoreService"):GetDataStore("CardsSaveV.3") PlayersCards = ds:GetAsync("CardsV.3")
game.Players.PlayerAdded:connect(function(Plr) repeat wait() until Plr.Character dss = ds:GetAsync(Plr.userId,PlayersCards) -- this will be a table dss ~= nil then for i=1, # dss do print("Cards found") local val = game.Lighting.Cards[v.Name]:Clone() val.Parent = game.Players[Plr.Name].Cards end else print("No cards found.") end end)
game.Players.PlayerRemoving:connect(function(Plr) print("Saving Game...") for i,v in pairs(game.Players[Plr].Cards:GetChildren()) do print(v.Name) table.insert(v.Name,PlayersCards) end ds:SetAsync(Plr.userId,PlayersCards) print("Game Saved!") end)
That should work but im not sure because im not at my pc at this time. |
|
|
| Report Abuse |
|
|
Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
|
| 27 Jan 2015 09:12 PM |
| Didn't work. Thank for for all this help btw, you are the first person in 3 weeks to even try and help me with this. |
|
|
| Report Abuse |
|
|
| |
|
|
| 28 Jan 2015 07:48 AM |
Let's take a look and what you are trying to do here, first you are assigning PlayerCards:
PlayerCards = ds:GetAsync("CardsV.3")
Now you are trying to get the async Plr.userId, but why do you have a second argument? GetAsync only takes 1 argument, the key the value is saved under, in this case you are using the userId of the joining player:
if ds:GetAsync(Plr.userId,PlayersCards) ~= nil then
Now moving on to the the removing event.
You are looping through a players cards and inserting them into PlayerCards. So I'm assuming PlayerCards is a table, I'm not sure if DataStores work like this, however since you setting the Plr.userId to PlayerCards anyway, I recommend making a new table, instead of using the PlayerCards variable, so like this:
game.Players.PlayerRemoving:connect(function(Plr) local Cards = {} print("Saving Game...") for i,v in pairs(game.Players[Plr].Cards:GetChildren()) do print(v.Name) table.insert(v.Name,Cards) end ds:SetAsync(Plr.userId,Cards) print("Game Saved!") end)
From looking at your code, I'm assuming you were trying to get the key userId, while using the value, when infact you didn't need it at all.
If my hunches are correct, here's a fixed up version of your code, reply back with any problems.
print("Save script loaded.") ds = game:GetService("DataStoreService"):GetDataStore("CardsSaveV.3") game.Players.PlayerAdded:connect(function(Plr) repeat wait() until Plr.Character local PlayerCards = ds:GetAsync(Plr.userId) if PlayerCards ~= nil then for i, v in pairs(PlayersCards) do print("Cards found") local val = game.Lighting.Cards[v.Name]:Clone() val.Parent = game.Players[Plr.Name].Cards end else print("No cards found.") end end)
game.Players.PlayerRemoving:connect(function(Plr) local Cards = {} print("Saving Game...") for i,v in pairs(game.Players[Plr].Cards:GetChildren()) do print(v.Name) table.insert(v.Name,Cards) end ds:SetAsync(Plr.userId,Cards) print("Game Saved!") end) |
|
|
| Report Abuse |
|
|
Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
|
| 28 Jan 2015 08:17 AM |
When using DataStore arn't you suppose to make the leaving and entering val the same so it know if it has data or not? Also I don't get any errors with yours, but it still prints "No cards found." no matter how many times I leave and enter again with cards in my inventory. |
|
|
| Report Abuse |
|
|
Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
|
| 28 Jan 2015 08:26 AM |
I see what you did there. Made the table then saved it once all the cards where inserted into it. |
|
|
| Report Abuse |
|
|
Codys4x4
|
  |
| Joined: 14 Oct 2006 |
| Total Posts: 2312 |
|
| |
|
|
| 28 Jan 2015 09:25 AM |
Heh, I think I found it!
print("Save script loaded.") ds = game:GetService("DataStoreService"):GetDataStore("CardsSaveV.3") game.Players.PlayerAdded:connect(function(Plr) repeat wait() until Plr.Character local PlayerCards = ds:GetAsync(Plr.userId) if PlayerCards ~= nil then for i, v in pairs(PlayersCards) do print("Cards found") local val = game.Lighting.Cards[v.Name]:Clone() val.Parent = game.Players[Plr.Name].Cards end else print("No cards found.") end end)
game.Players.PlayerRemoving:connect(function(Plr) local Cards = {} print("Saving Game...") for i,v in pairs(game.Players[Plr.Name].Cards:GetChildren()) do --You had game.Players[Plr].Cards:GetChildren() (In other words, you forgot .Name) print(v.Name) table.insert(v.Name,Cards) end ds:SetAsync(Plr.userId,Cards) print("Game Saved!") end) |
|
|
| Report Abuse |
|
|
|
| 28 Jan 2015 10:10 AM |
Here I made a version for debugging purposes:
print("Save script loaded.") ds = game:GetService("DataStoreService"):GetDataStore("CardsSaveV.3") print("ds has been set") game.Players.PlayerAdded:connect(function(Plr) print("A player has been added") Plr.CharacterAdded:wait() local PlayerCards = ds:GetAsync(Plr.userId) print(PlayerCards) if PlayerCards ~= nil then print(type(PlayerCards)) print(#PlayerCards) for i, v in pairs(PlayersCards) do print("Cards found", i) local val = game.Lighting.Cards[v]:Clone() --You said v.Name, we only inserted the names of tools, not tools themselves. print(v.Name .. " cloned") val.Parent = game.Players[Plr.Name].Cards print(v.Name .. " parented") end print("Loop end") else print("No cards found.") end end) print("Player added end")
game.Players.PlayerRemoving:connect(function(Plr) print("Player removing") local Cards = {} print("Cards table made") print("Saving Game...") for i,v in pairs(game.Players[Plr.Name].Cards:GetChildren()) do print("Looping through") print(v.Name) table.insert(v.Name,Cards) print("Inserted") end print("Loop end") ds:SetAsync(Plr.userId,Cards) print("Cards saved") print("Game Saved!") end) print("Player removing end") print("Script end") |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2015 05:25 AM |
| So did you find the problem? |
|
|
| Report Abuse |
|
|