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
|
  |
| 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 |
|
|
|
| 16 Apr 2016 03:14 AM |
Hey I am so confused...
Is Inventory a value or is Inventory = _G["Inventory"][Player.Name]?
|
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|