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: Any reason why this won't work?

Previous Thread :: Next Thread 
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 10:29 PM
inventory = {}
maxItems = 15 -- change this to how many items you can store
currentItems = #inventory

function addItem(x)
currentItems = #inventory
if (currentItems < maxItems) then
local item = table.insert(inventory, (currentItems + 1), x)
print(x.. ' added')
currentItems = #inventory
local g = script.Parent.Inventory:GetChildren()
local objec = game.Lighting:FindFirstChild(x)
local object = objec:clone()
for i = 1, #g do
if (g[i].Name == (currentItems + 1)) then
g[i].Text.Text = object.Name
object.Parent = script.Parent.Backpack
break
end
end
else
print('Inventory full')
end
end

addItem("Sword")

--No output
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 10:34 PM
I have "Sword" in Lighting.
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 10:40 PM
Come on. Please answer. Don't be shy.
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 10:45 PM
Anyone still up?
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
28 Jun 2014 10:48 PM
inventory = {}
maxItems = 15 -- change this to how many items you can store
currentItems = #inventory

function addItem(x)
currentItems = #inventory
if (currentItems < maxItems) then
local item = table.insert(inventory, (currentItems + 1), x)
print(x.. ' added')
currentItems = #inventory
local g = script.Parent.Inventory:GetChildren()
local objec = game.Lighting:FindFirstChild(x)
local object = objec:clone() --- You forgot the t in object.
for i = 1, #g do
if (g[i].Name == (currentItems + 1)) then
g[i].Text.Text = object.Name
object.Parent = script.Parent.Backpack
break
end
end
else
print('Inventory full')
end
end

addItem("Sword")
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 10:49 PM
local objec = game.Lighting:FindFirstChild(x)
local object = objec:clone() --- You forgot the t in object. Nope
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
28 Jun 2014 10:49 PM
owaitno

That's a variable, my bad.
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 10:50 PM
I don't get it either, lol. I used some real hacky stuff here.
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
28 Jun 2014 10:52 PM
inventory = {}
maxItems = 15 -- change this to how many items you can store
currentItems = #inventory

function addItem(x)
currentItems = #inventory -- Well, it seems you are calling the number of items, and not the items in the table, or atleast, that's what i've been taught/learned.

if (currentItems < maxItems) then
local item = table.insert(inventory, (currentItems + 1), x)
print(x.. ' added')
currentItems = #inventory
local g = script.Parent.Inventory:GetChildren()
local objec = game.Lighting:FindFirstChild(x)
local object = objec:clone()
for i = 1, #g do
if (g[i].Name == (currentItems + 1)) then
g[i].Text.Text = object.Name
object.Parent = script.Parent.Backpack
break
end
end
else
print('Inventory full')
end
end

addItem("Sword")
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 10:54 PM
Well that's on purpose. It's kind of complicated.
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 10:56 PM
If you need the model, I can give it to you, I was gonna make it open source anyway
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 10:58 PM
http://www.roblox.com/GUI-Inventory-System-item?id=163734799

check it out.
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
28 Jun 2014 11:00 PM
Let me just say; it looks marvelous.
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 11:00 PM
The GUI?
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
28 Jun 2014 11:01 PM
Your probably did it on purpose, but you have

inventory = {}
maxItems = 15 -- change this to how many items you can store
currentItems = #inventory

twice in the script.
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 11:02 PM
I do? Where?
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 11:04 PM
I must've added that at the last minute. And that didn't fix it :(
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 11:13 PM
You still there?
Report Abuse
Krosskode is not online. Krosskode
Joined: 26 Aug 2010
Total Posts: 11001
28 Jun 2014 11:14 PM
I'm trying to figure out why it won't work; it looks perfectly fine.
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 11:18 PM
I found one error:

local g = script.Parent.Inventory:GetChildren()
Instead of:
local g = script.Parent.Inventory.Holder_1:GetChildren()

Still won't work. Hmmm.
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 11:20 PM
I wish oysi was online. He/she would snap this in a matter of seconds. :(
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
28 Jun 2014 11:43 PM
This is what I have so far:

inventory = {}
maxItems = 15 -- change this to how many items you can store
currentItems = #inventory

function addItem(x)
currentItems = #inventory
if (currentItems < maxItems) then
local item = table.insert(inventory, (currentItems + 1), x)
print(x.. ' added')
currentItems = #inventory
local g = script.Parent.Inventory.Holder_1:GetChildren()
local objec = game.Lighting:FindFirstChild(x)
local object = objec:clone()
for i = 1, #g do
if (g[i].Name == (currentItems + 1)) then
g[i].Text.Text = object.Name
object.Parent = script.Parent.Backpack
break
end
end
else
print('Inventory full')
end
end

function removeItem(y)
currentItems = #inventory
if (currentItems < 1) then
print('Nothing to remove')
else
for i = 1, #inventory do
if inventory[i] == y then
table.remove(inventory, i)
print(y.. ' removed')
break
end
end
currentItems = #inventory
end
end

addItem("Sword")
Report Abuse
TheBoyOnTheBlock is not online. TheBoyOnTheBlock
Joined: 09 Nov 2013
Total Posts: 341
29 Jun 2014 12:26 AM
found a fix yet?
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