Attempt to call a nil value

I Made a script but it gets this error

Players.spot64528.PlayerGui.SoftShutdown.Frame.LocalScript:38: attempt to call a nil value - Client - LocalScript:38
20:36:25.610 Stack Begin - Studio
20:36:25.611 Script ‘Players.spot64528.PlayerGui.SoftShutdown.Frame.LocalScript’, Line 38 - Studio - LocalScript:38
20:36:25.611 Stack End

Packing Controller:

local module = {}
local PackedAssets = {}
local is_success, error_message = pcall(function()

end)

--if is_success == true then print("Success!") end
function movetostore(ov)
	local part = ov
	part.Parent = game.ServerStorage
	local is_success, error_message = pcall(function()

	end)

	table.insert(PackedAssets,{ov})
	if is_success == true then
		print("[Packing Controller] Success!")
	else
		print("[Packing Controller]",error_message)

	end
end

return module


Local Script:

--[[ SERVICES ]]--
local is_success, error_message = pcall(function()

end)
local ReplicatedStorage = game.ReplicatedStorage
local TweenService = game:GetService("TweenService")
local StarterGui = game:GetService("StarterGui")
local Packing_Controller = require(ReplicatedStorage["Packing Controller"])
--[[ TWEENS/LOCALS ]]--

local LoadingImage = script.Parent.ImageLabel
local tweenInfo = TweenInfo.new(4, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1)
local tween = TweenService:Create(LoadingImage, tweenInfo, {Rotation=360})
tween:Play()


	
	


--[[ TOP BAR DISABLER ]]--

StarterGui:SetCore("TopbarEnabled",false)
StarterGui:SetCoreGuiEnabled("All",false)

--[[ TEXT CHANGER ]]--

while true do
	script.Parent.TextLabel.Text = "Teleporting."
	wait(0.5)
	script.Parent.TextLabel.Text = "Teleporting.."
	wait(0.5)
	script.Parent.TextLabel.Text = "Teleporting..."
	wait(0.5)
	script.Parent.TextLabel.Text = "DeLoading Assets."
	wait(0.5)

	Packing_Controller:movetostore(game.Workspace.Baseplate)
	script.Parent.TextLabel.Text = "DeLoading Assets.."
	wait(0.5)
	script.Parent.TextLabel.Text = "DeLoading Assets..."
	wait(0.5)
end

you never made “movetostore” part of the module.

local module = {}
local PackedAssets = {}
local is_success, error_message = pcall(function()

end)

--if is_success == true then print("Success!") end
function module:movetostore(ov)
	local part = ov
	part.Parent = game.ServerStorage
	local is_success, error_message = pcall(function()

	end)

	table.insert(PackedAssets,{ov})
	if is_success == true then
		print("[Packing Controller] Success!")
	else
		print("[Packing Controller]",error_message)

	end
end

return module

What do you mean? I Did?

`function movetostore(ov)
local part = ov
part.Parent = game.ServerStorage
local is_success, error_message = pcall(function()

end)

table.insert(PackedAssets,{ov})
if is_success == true then
	print("[Packing Controller] Success!")
else
	print("[Packing Controller]",error_message)

end

end
`

yes, but you are calling “Packing_Controller:movetostore()

right here, you returned the module,

which right here, you defined as an empty table.

this function was never put into the module before returning it.

Can You Fix it I do not understand

I believe I gave the answer right here?

1 Like

Omg TYSM I was so Confused!
It work

function module.movetostore(ov)
	local part = ov
	part.Parent = game.ServerStorage
	local is_success, error_message = pcall(function()

	end)

	table.insert(PackedAssets,{ov})
	if is_success == true then
		print("[Packing Controller] Success!")
	else
		print("[Packing Controller]",error_message)

	end
end

I’m going to assume that in this instance the self object (the instance through which the method is called) isn’t required (as the implicit self parameter or often referred to as the self function variable is not referenced/used from within the function’s definition), so the dot operator should suffice (it’s also slightly more efficient to define a function in this way).

1 Like