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 » Scripting Helpers
Home Search
 

Re: JSON is really letting me down.

Previous Thread :: Next Thread 
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
01 May 2014 01:33 PM
I have a shop script that distributes items based off a table that gets JSON'ed and reverse JSON'ed. Unfortunately, when I reverse JSON the string, it still says it can't use :GetChildren () on a string.

Here's my code:
util = assert (LoadLibrary ('RbxUtility'));
stringy = player.StuffKeeper;
UnJSONing = util.DecodeJSON (stringy.Value);

game.Players.LocalPlayer.Changed:connect (function ()
if game.Players.LocalPlayer.TeamColor == BrickColor.new ('Really blue') then
for i,v in pairs (UnJSONing:GetChildren) do -- errors
--stuff
end
end
end)
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
01 May 2014 01:41 PM
You also cant use :GetChildren() on a table ._.
Report Abuse
brinkokevin is not online. brinkokevin
Joined: 25 Jul 2012
Total Posts: 1673
01 May 2014 01:44 PM

UnJSONing = LoadLibrary("RbxUtility").DecodeJSON(player.StuffKeeper.Value)

game.Players.LocalPlayer.Changed:connect(function()
if game.Players.LocalPlayer.TeamColor == BrickColor.new ('Really blue') then
for i=1,#UnJSONing do
--stuff
end
end
end)
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
01 May 2014 01:49 PM
I know, I know. I fixed that part already, but it just said that you can't use "pairs on a string".
Report Abuse
brinkokevin is not online. brinkokevin
Joined: 25 Jul 2012
Total Posts: 1673
01 May 2014 01:51 PM
that script i posted didnt work ?
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
01 May 2014 01:53 PM
I tested the #UnJSONing method. The only problem is now I'm not sure how to refer to a single object in the string.

This is --stuff:
for i,gear in pairs (game.ReplicatedStorage:GetChildren ()) do
if v.Name == gear.Name and v then
gear:Clone ().Parent = game.Players.LocalPlayer.Backpack;
end
end
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
01 May 2014 02:03 PM
bump :c
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
01 May 2014 02:11 PM
For shops I just use a string and gmatch. I find it much more reliable
Report Abuse
brinkokevin is not online. brinkokevin
Joined: 25 Jul 2012
Total Posts: 1673
01 May 2014 02:20 PM
g = LoadLibrary("RbxUtility").DecodeJSON(player.StuffKeeper.Value)

game.Players.LocalPlayer.Changed:connect(function()
if game.Players.LocalPlayer.TeamColor == BrickColor.new ('Really blue') then
for i=1,#g do
for i,gear in pairs (game.ReplicatedStorage:GetChildren ()) do
if g[i] and g[i].Name == gear.Name then
gear:Clone().Parent = game.Players.LocalPlayer.Backpack;
end
end
end
end
end)
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
01 May 2014 03:30 PM
I forgot about UnJSONing[i], thanks.

Wazap, could you explain that method? It sounds easier.
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
01 May 2014 03:32 PM
It doesn't like it for some reason.

When I replace if v.Name with UnJSONing[i].Name, it gives me:
attempt to index field ? (a nil value)
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
01 May 2014 03:38 PM
Set it up like this

local shopItems = "Sword,Lightning rod,Pandas,Potatoes,Koalas" (no space in between commas preferably)

for s in shopItems:gmatch("%P+") do
game.ServerStorage(s):clone().Parent = workspace
end

Something like that
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
01 May 2014 03:40 PM
1) I need to get better at string manipulation
2) How do you detect if a player has purchased the item?
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
01 May 2014 03:41 PM
Why not use a table instead of a string?
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
01 May 2014 03:42 PM
I do. I just have to use JSON so that person comes back with the items they've purchased after they left.
Report Abuse
brinkokevin is not online. brinkokevin
Joined: 25 Jul 2012
Total Posts: 1673
01 May 2014 03:43 PM
oh i understand what your trying to do btw you could also create int value for each wepon and then if int.Value == 1 then clonewepon else nowepon and just symply change that value to 1
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
01 May 2014 03:44 PM
what the heck are you trying to say?

IntValue? What's this method? BoolValue for every item is my last resort.
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
01 May 2014 03:46 PM
Use a StringValue called inventory and use StringValue.Value:match(s)
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
01 May 2014 03:46 PM
So, when someone buys something, it adds that name to the string?
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
01 May 2014 03:47 PM
Yup.
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
01 May 2014 03:49 PM
so..

function bought (item)
inventory = inventory..","..item.Name
end

?
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
01 May 2014 03:51 PM
inventory.Value = inventory.Value..name
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
01 May 2014 03:52 PM
Well... yeah. I'll try it!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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