|
| 01 Sep 2017 09:28 PM |
I'm new to using module scripts and tables but ive been trying to make a simple buy button and i keep getting the error message attempt to index field '?' (a nil value). Does anybody know why.
My script: local playerLeaderstats = {}
playerLeaderstats.add = function(player) playerLeaderstats[player] = {} playerLeaderstats[player]["Money"] = 0 # #l################################## 0 - kills value idk y its blocked local stats = Instance.new('Folder',player) stats.Name = 'leaderstats' local kills = Instance.new('IntValue',stats) kills.Name = 'Kills' kills.Value = playerLeaderstats[player]["Kills"] local money = Instance.new('IntValue',stats) money.Name = 'Credits' playerLeaderstats[player]["Money"] = 100 money.Value = playerLeaderstats[player]["Money"] end
playerLeaderstats.Buy = function(price,Item,player) local money = player.leaderstats.Credits local slots = player.CInventory:FindFirstChild("CaseSlots") print("got em "..price) player.PlayerGui.Buy.Enabled = false workspace.CurrentCamera.Blur:Remove() player.PlayerGui.Logos.Enabled = true player.PlayerGui["Cash/Case"].Enabled = true if playerLeaderstats[player]["Money"] >= price then -- This is where im getting the error message print("Rich kid") playerLeaderstats[player]["Money"] = playerLeaderstats[player]["Money"] - price print (playerLeaderstats[player]["Money"]) money.Value = playerLeaderstats[player]["Money"] for i = 1,10 do local Slot = slots:WaitForChild("Slot"..i) if Slot.Equip.Value ~= Item then if Slot.Equip.Value == "" then Slot.Equip.Value = Item Slot.Amount.Value = 1 break else print("Already Equipped") end else Slot.Amount.Value = Slot.Amount.Value + 1 break end end player.PlayerGui.Cant.Can:TweenPosition(UDim2.new(1,0,0.85,0),"In","Quint",0.5,true) wait(2) player.PlayerGui.Cant.Can:TweenPosition(UDim2.new(1.5,0,0.85,0),"In","Quint",0.5,true) else money.Value = playerLeaderstats[player]["Money"] player.PlayerGui.Cant.Buy:TweenPosition(UDim2.new(1,0,0.85,0),"In","Quint",0.5,true) wait(2) player.PlayerGui.Cant.Buy:TweenPosition(UDim2.new(1.5,0,0.85,0),"In","Quint",0.5,true) end end
return playerLeaderstats |
|
|
| Report Abuse |
|
|
| |
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 01 Sep 2017 09:51 PM |
| which line throws the error? |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2017 09:57 PM |
| the line i marked with -- This is where im getting the error message |
|
|
| Report Abuse |
|
|
|
| 01 Sep 2017 09:59 PM |
You're trying to index a nil value. That's what the error says.
|
|
|
| Report Abuse |
|
|
|
| 01 Sep 2017 10:00 PM |
| how do i fix it then # it works when i dont create a test server |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 01 Sep 2017 10:39 PM |
well we'd help but the marked line is censored..
|
|
|
| Report Abuse |
|
|
|
| 02 Sep 2017 06:19 AM |
| is it? well its the line if playerLeaderstats[player]["Money"] >= price then |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
| |
|
|
| 02 Sep 2017 08:53 AM |
| i did in the functions brackets - playerLeaderstats.Buy = function(price.item,player) |
|
|
| Report Abuse |
|
|
| |
|
| |
|
Avallex
|
  |
| Joined: 13 Mar 2013 |
| Total Posts: 31 |
|
|
| 02 Sep 2017 10:33 AM |
| You're not giving us a lot to work with.. |
|
|
| Report Abuse |
|
|
| |
|
|
| 02 Sep 2017 10:51 AM |
probably because of 'playerLeaderstats[player]["Money"]'.
It might be saying 'player' is nil. |
|
|
| Report Abuse |
|
|
| |
|
|
| 02 Sep 2017 11:18 AM |
| Are you including the player argument when you're calling the Buy function? |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2017 11:50 AM |
| yea i am - ################################ Case",game.Players.LocalPlayer) |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2017 11:59 AM |
| the tags are just calling the function |
|
|
| Report Abuse |
|
|
|
| 02 Sep 2017 12:03 PM |
| The module is required and the function is fired from a localscript right? |
|
|
| Report Abuse |
|
|