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 » Scripters
Home Search
 

Help with inventory?

Previous Thread :: Next Thread 
KordGamer is online. KordGamer
Joined: 23 Oct 2013
Total Posts: 249
16 Apr 2016 03:04 AM
So I'm experimenting with ways that I can add an item to a certain player's inventory, such as gamepasses, badges and player names.

I want to mainly use this as a script that gives a player an item if they have a gamepass, but for now I'm experimenting with player names.

It gives an error, and I've tried a lot of things to fix it.

Here's the script:


game.Players.PlayerAdded:connect(function(Player)
if Player.Name == "KordGamer" then
local ItemNameU = "Fetching gamepass items."
print(""..ItemNameU)
local Item = "Boogie Woogie Plant of Doom"
local RealItem = game.ReplicatedStorage.Items:FindFirstChild(Item)
print(""..RealItem.Name)
if RealItem then

local Inventory = _G["Inventory"][Player.Name]

if Inventory[RealItem.ItemId.Value].Quantity then
Inventory[RealItem.ItemId.Value].Quantity = 1
end

_G["Inventory"][Player.Name] = Inventory
InventoryChanged:FireClient(Player)
return true
end
end
return false
end)


The error is - ServerScriptService.GamepassTest:34: attempt to index local 'Inventory' (a nil value)

Thanks for any help.


"If it's not broken, Don't fix it."
Report Abuse
KordGamer is online. KordGamer
Joined: 23 Oct 2013
Total Posts: 249
16 Apr 2016 03:12 AM
bumpa bumpa


"If it's not broken, Don't fix it."
Report Abuse
FrankieTheDino is online. FrankieTheDino
Joined: 27 Jul 2008
Total Posts: 603
16 Apr 2016 03:14 AM
Hey I am so confused...


Is Inventory a value or is Inventory = _G["Inventory"][Player.Name]?


Report Abuse
FrankieTheDino is online. FrankieTheDino
Joined: 27 Jul 2008
Total Posts: 603
16 Apr 2016 03:16 AM
The reason why it is returning nil, is because Inventory is nil....


You didn't set it to anything e.e


Oh wait, your trying to make Inventory a varible with _G["Inventory"][Player.Name]?


Report Abuse
FrankieTheDino is online. FrankieTheDino
Joined: 27 Jul 2008
Total Posts: 603
16 Apr 2016 03:21 AM
Oh I figured it out....

So what happen was, your _G["Inventory"] wasn't created yet.


Put this in the front of your script:

_G["Inventory"] = ''


That would solve all your problems :)


Report Abuse
KordGamer is online. KordGamer
Joined: 23 Oct 2013
Total Posts: 249
16 Apr 2016 03:27 AM
Thanks for the help, but it still doesn't work.

I had _G["Inventory"] = {} at the beginning already.


"If it's not broken, Don't fix it."
Report Abuse
FrankieTheDino is online. FrankieTheDino
Joined: 27 Jul 2008
Total Posts: 603
16 Apr 2016 03:37 AM
Hmm... I'm not really sure. This is the script I made to hopefully help you.



_G["Inventory"] = {}

game.Players.PlayerAdded:connect(function(Player)
if Player.Name == "Player1" then
local ItemNameU = "Fetching gamepass items."
print(""..ItemNameU)
local Item = "Boogie Woogie Plant of Doom"
local RealItem = Item
if RealItem then
local Inventory = _G["Inventory"][Player.Name]

_G["Inventory"][Player.Name] = Inventory

return true
end
end
return false
end)


This seemed like it worked. Did I do anything different that may have effected it?


Report Abuse
FrankieTheDino is online. FrankieTheDino
Joined: 27 Jul 2008
Total Posts: 603
16 Apr 2016 03:41 AM
I also did this:

_G["Inventory"] = {}

game.Players.PlayerAdded:connect(function(Player)
if Player.Name == "Player1" then
local ItemNameU = "Fetching gamepass items."
print(""..ItemNameU)
local Item = "Boogie Woogie Plant of Doom"
local RealItem = Item
if RealItem then

_G["Inventory"][Player.Name] = RealItem
print( _G["Inventory"][Player.Name])

return true
end
end
return false
end)



And it printed out Boogie Woogie Plant of Doom without any issue at all. Is that what you want?


Report Abuse
KordGamer is online. KordGamer
Joined: 23 Oct 2013
Total Posts: 249
16 Apr 2016 05:41 AM
I wanted to add to 1 to the quantity of Boogie Woogie Plant of Doom in Inventory.


"If it's not broken, Don't fix it."
Report Abuse
KordGamer is online. KordGamer
Joined: 23 Oct 2013
Total Posts: 249
16 Apr 2016 07:29 AM
Nvm fixed it


"If it's not broken, Don't fix it."
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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