Attempt to call a nil value

(sorry if i do something wrong this is my first ever post)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    This script keeps giving me an error and I want to fix it

  2. What is the issue? Include screenshots / videos if possible!
    The script keeps giving this error: “Players.doctorpepper126.PlayerGui.AddItem:9: attempt to call a nil value”

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    The solutions on the hub didnt work for me

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Script:

wait(6)
local reqMod = require(game.ReplicatedStorage["InventoryHandler"])

reqMod:AddItemToInventory(script.Parent.Parent, script:WaitForChild("sword"))
1 Like

what is

can you give that?
i think the error is there

First to understand the problem better, the error appears once “AddItemInventory” is called or the passed arguments are incorrect?

Than waiting 6 seconds (unless it’s needed for specific case) you could use “WaitForChild” to be sure the module is available before using it.

This code looks mostly good to me, however I believe the reason this error is occurring is the fact that you used a colon to call a function in a ModuleScript, and, if I am not mistaken, functions in ModuleScripts should be called using a dot instead, meaning that rather than using reqMod:AddItemToInventory([parameters]), you should use reqMod.AddItemToInventory([parameters]).