dennis Posted September 22, 2014 Share Posted September 22, 2014 Hey all, I'm following project saturn tutorial series and now there is this problem with creating the inventory. function Script:Use(player) local playerInventory = player.script:GetInventory() if playerInventory == nil then error("No inventory") end System:Print("We got an inventory") if not playerInventory:IsFull() then System:Print("We place the bottle inside the inventory") end end it's a real pain to find out what the problem is because the error I'm getting is: "C:/Users/Dennis/Documents/Leadwerks/Projects/..." : 3 : attempt to index local 'player' (a nil value) But I already declared the player inside Use right? Can somebody please help? Cheers Quote Link to comment Share on other sites More sharing options...
Rick Posted September 22, 2014 Share Posted September 22, 2014 It's saying that the value of the player variable is nil. So yes while you declared it as a parameter to the function, whatever calls this function must pass in a valid (non nil) value to the player variable. It would seem it's not. So look at whatever calls this function and see what it's passing into it. Quote Link to comment Share on other sites More sharing options...
dennis Posted September 22, 2014 Author Share Posted September 22, 2014 I got this: function Script:GetInventory() return self.entity:FindChild("PlayerInventory").script end inside FPSPlayer.lua but it only returns the problem when using the prop I placed in my scene. Quote Link to comment Share on other sites More sharing options...
Rick Posted September 22, 2014 Share Posted September 22, 2014 No I mean what calls your Script:Use() function that is passing in the player value to it's parameter variable? It doesn't even get to call the GetInventory() function because your player variable is nil. That's what the error is telling you. So you have to look at why your player variable is nil. You declare the player variable as a function parameter to the Use() function. So whatever is calling that Use() function should be passing something in, but whatever it's passing in is nil or it's not passing anything in which the default value is then set to nil. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted September 22, 2014 Share Posted September 22, 2014 I have seen this happening before. If you are following the entire tutorial serie, then at one point you changed the following line in the fpsplayer.lua to this. (around line 290) --Use the object, whatever it may be usableentity.script:Use(self.entity) The reason why it probably no longer works: When Leadwerks has an official update that changes the FPSplayer.lua, it replaces your lua file with the new one. That means that all your changes so far, are now gone (You can access the backup which is in the same folder). If an update has been pushed by Leadwerks that changes the script (somewhere last month the player script has been updated), then the line looks as follows: --Use the object, whatever it may be usableentity.script:Use() It is a quite annoying so I am going to switch to a separate FPSplayer script in order to prevent this problem from happening again. Quote Link to comment Share on other sites More sharing options...
dennis Posted September 23, 2014 Author Share Posted September 23, 2014 aggror, you saved my day! I was looking for this for like 6 hours :/ it works now Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted September 23, 2014 Share Posted September 23, 2014 No problem, but Rick actually stated the problem perfectly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.