" attempt to index nil with 'Position' " in Modules

Hello Programmers,
Could someone possible help me figure out why this error occurred and how I can fix it?

Error Message:

Script grabbing the object.
function module:create_Basic_Frame(player : Player, gui : ScreenGui, Title : string, Info : string)
	local Frame = nil
	
	local created, err = pcall(function()
		if player and gui and Title and Info then
			Frame = script:WaitForChild("Frame_Folder"):WaitForChild("Basic_Notif"):Clone()
		
			Frame:WaitForChild("Title").Text = Title
			Frame:WaitForChild("Info").Text = Info
			
			Frame.Parent = gui:WaitForChild("List")

			Frame.Notification_Sound:Play()
			
			Animate_Gui(gui, Frame)
		end
	end)
	
	if created then
		warn("Succesfully created Frame!")
		return Frame
	else
		error("An error occured creating Frame: ", err)
	end
end
Script receiving Object
function Notif_Mod.Basic_Notification(player : Player, Title : string, Info : string)
	if player and Title and Info then
		if player:IsA("Player") then -- Checks if player is valid
			if not player.PlayerGui:FindFirstChild("NotifGui") then Notif_Mod.Add_NotifGui(player) end
			
			local gui = player.PlayerGui:FindFirstChild("NotifGui")
			
			local Frame = Frame_Creator.create_Basic_Frame(player, gui, Title, Info)
			
			Add_Table(player, Title, Frame)
			
			task.delay(7.5, function()
				game:GetService("TweenService"):Create(Frame, TweenInfo.new(0.5), {Position = UDim2.new(0, Frame.Position.X.Offset, Frame.Position.Y.Scale, Frame.Position.Y.Offset)}):Play()
				task.wait(1)
				Frame:Remove()
			end)
		else
			error("Player is either invalid or not a player!") -- Error Message
		end
	else
		warn("One of the values are missing or nil!")
	end
end

I suspect that one of these conditions aren’t being met.

When you are checking if the frame exists, you are actually only checking that an error didn’t occur. The if statement not ahving its conditions met isn’t raising an error, hence the pcall isn’t erroring. You should try doing if created and frame then instead.


If you print out player, gui, Title, and Info, are any of them listed as nil?

You’re not calling module:create_Basic_Frame correctly. You used the colon operator to designate the function as a component of the module table. This changes the way the function behaves through the introduction of an implicit parameter that consumes the first argument of future function calls. To understand this at a greater detail, read my reply to another post. To fix the issue, make one of the two following changes:

function module:create_Basic_Frame(...)
-- To
function module.create_Basic_Frame(...)

Or

Frame_Creator.create_Basic_Frame(...)
-- To
Frame_Creator:create_Basic_Frame(...)

TL;DR: Make sure you call the function with the same operator used in its function signature

2 Likes

Thank you so much for giving these tips, this really helps me out a ton! :+1:

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