Modulescript got nil on reading parameter

  1. What do you want to achieve?
    I want to fix this bug

  2. What is the issue?
    When I call a function that in the Modulescript and Passing the Player profile.Data as argument and the modulescript throw the error to the output that the data parameter is “nil”

  3. What solutions have you tried so far?
    I have tried printing profile.Data and it not return “nil” it return the table of player data.
    I have search for the solution but my problem still not be fix.

Here is some script on the SERVER SCRIPT

local function HatchEgg(player: Player, egg: string, amount: number)
	local profile = PlayerData.Profiles[player]
	if not profile then return end
	local eggConfig = EggsConfig.GetConfig(egg)
	if not eggConfig then return end
	local amountOfHatches = if amount > 8 then 8 else amount
	local price = eggConfig.Price
        print(profile.Data) -- it returned the table of PlayerData
	if ShopConfig.DoesPlayerOwnSubscription(true, "Exclusive Plus Member", profile.Data) then
		price -= math.floor(price * (20/100))
	elseif ShopConfig.DoesPlayerOwnSubscription(true, "Exclusive Premium Member", profile.Data) then
		price -= math.floor(price * (25/100))
-- The ShopConfig.DoesPlayerOwnSubscription(...) throw the error

	price *= amountOfHatches

Here is some script on the MODULE SCRIPT

function Shop.DoesPlayerOwnSubscription(findFromName: boolean, id: string, data)
        print(data) -- it returned nil
	id = if not findFromName then id else Shop.GetSubscriptionIDFromName(id)
	return data.Subscriptions[id]

You can ask more information.
Thank you for helping me!

1 Like

Do you have a return data inside your function? return is what tells the function to give back some information, in which you have to add what data you want it to return.

Code after a return won’t run, the function stops at return, so make sure to run it at the end or separate to the code you have after it.

can you please tell the error message or provide us more code as the code you gave is no where near enough for us to understand anything

the only thing I can guess where it errored it is


are you sure data.Subscriptions is a valid indexable object?

Yes, other function on the module script can index “Subscriptions” table

Yes, But I return the data at the bottom of function

weird, what was the error message?

Sorry for late reply
The error message: “Attempt to index nil with ‘Subscriptions’”

It work now. I’m not sure what it happened LOL

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.