generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Game Design
Home Search
 

Re: Need some help here, not sure what the problem is.

Previous Thread :: Next Thread 
Codys4x4 is not online. 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
GodShowsTheWay is not online. GodShowsTheWay
Joined: 27 Oct 2014
Total Posts: 7180
26 Jan 2015 10:04 PM
um the problem is on line 9:


print("im not a mexican")
Report Abuse
Codys4x4 is not online. Codys4x4
Joined: 14 Oct 2006
Total Posts: 2312
26 Jan 2015 10:38 PM
Please...
Report Abuse
Codys4x4 is not online. Codys4x4
Joined: 14 Oct 2006
Total Posts: 2312
27 Jan 2015 07:31 AM
Bump
Report Abuse
Codys4x4 is not online. Codys4x4
Joined: 14 Oct 2006
Total Posts: 2312
27 Jan 2015 12:40 PM
Bump
Report Abuse
Codys4x4 is not online. Codys4x4
Joined: 14 Oct 2006
Total Posts: 2312
27 Jan 2015 01:28 PM
Bump
Report Abuse
Codys4x4 is not online. Codys4x4
Joined: 14 Oct 2006
Total Posts: 2312
27 Jan 2015 05:32 PM
Bump
Report Abuse
shadownetwork is not online. shadownetwork
Joined: 06 Feb 2014
Total Posts: 296
27 Jan 2015 05:36 PM
what is the output?
Report Abuse
Codys4x4 is not online. 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 is not online. Codys4x4
Joined: 14 Oct 2006
Total Posts: 2312
27 Jan 2015 06:10 PM
Bump
Report Abuse
shadownetwork is not online. shadownetwork
Joined: 06 Feb 2014
Total Posts: 296
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 is not online. 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
shadownetwork is not online. shadownetwork
Joined: 06 Feb 2014
Total Posts: 296
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 is not online. 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 is not online. 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
shadownetwork is not online. shadownetwork
Joined: 06 Feb 2014
Total Posts: 296
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 is not online. 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
shadownetwork is not online. shadownetwork
Joined: 06 Feb 2014
Total Posts: 296
27 Jan 2015 10:14 PM
Did it give an output?
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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 is not online. 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 is not online. 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 is not online. Codys4x4
Joined: 14 Oct 2006
Total Posts: 2312
28 Jan 2015 08:43 AM
Bump
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
31 Jan 2015 05:25 AM
So did you find the problem?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Game Design
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image