Attempt to call a nil value

I made a npc move script with module script and main script says “attempt to call a nil value”

local move = require(game.ServerStorage:WaitForChild("Move NPC"))

local setting = {
	["Use"] = "Use"; 
	["AfterUse"] = "Use";
	["Time"] = "3";
}

local use = Instance.new("BoolValue", script)
use.Name = "IsUsing"
use.Value = false

local afteruse = Instance.new("BoolValue", script)
afteruse.Name = "AfterUsing"
afteruse.Value = false

local afterusetime = Instance.new("BoolValue", script)
afterusetime.Name = "AfterUsingTime"
afterusetime.Value = false

if setting["Use"] == "Use" then
	use.Value = true
	move.Start(use.Value) -- error
else
	use.Value = false
	end

if setting["AfterUse"] == "Use" then
	afteruse.Value = true
else
	afteruse.Value = false
end

if setting["AfterUse"] == "Use" then
	afterusetime.Value = true
else
	afterusetime.Value = false
	end
2 Likes

can you share move.Start function form module

1 Like
local move = {
	["NPC Name"] = "NPC";
	["Type"] = "Folder";
	["Type Name"] = "MoveParts";
	["Cooldown"] = "1"; 
	["Repeat"] = "Use";
}

print(move)

local repeat_value = Instance.new("BoolValue", script)
repeat_value.Name = "IsRepeating"
repeat_value.Value = false

if move["Repeat"] == "Use" then
	repeat_value.Value = true
else
	repeat_value.Value = false
end

local npc = workspace:WaitForChild(move["NPC Name"])
local humanoid = npc:WaitForChild("Humanoid")
local moveparts
local moveparts_type

if move["Type"] == "Folder" then
	moveparts_type = "Folder"
elseif move["Type"] == "Model" then
	moveparts_type = "Model"
else
	warn("There is no folder or model")
end

for work, parts in pairs(workspace:GetChildren()) do
	if parts:IsA(moveparts_type) and parts.Name == move["Type Name"] then
	for i,v in pairs(parts:GetChildren()) do
	if v:IsA("Part") then
			moveparts = v
			end
		end
		end
end

local function loop()
	while true do
		task.wait(1)
		if move["Repeat"] == "Use" and repeat_value.Value == false then
			repeat_value = true
		end
		if move["Repeat"] == "NotUse" and repeat_value.Value == true then
			repeat_value = false
		end
	end
end

spawn(loop)

local function Move()
	while true do
	if move["Repeat"] == "Use" and repeat_value.Value == true then
	humanoid:MoveTo(moveparts.Position)
	humanoid.MoveToFinished:Wait()
	task.wait(move["Cooldown"])
	end
end

for q,c in pairs(npc:GetChildren()) do
	if c:IsA("Part") then
		if c.Name == "HumanoidRootPart" then
			if c.Anchored == true then
				c.Anchored = false
			end
		end
	end
end

	function move.Start(use) -- error
		print(use)
	if use == true then
		if move["Repeat"] == "Use" and repeat_value.Value == true then
			spawn(move)
			else
			humanoid:MoveTo(moveparts.Position)
			humanoid.MoveToFinished:Wait()
		end
	else
		script:Destroy()
		end
	end
	end




return move

umm no idea why this is happening, even I am getting similar error in my script when I pass an argument to a function in another module. The worse part is I still didn’t get the fix

1 Like

Why do you have Move.Start() inside of Move() in the modulescript?

1 Like

? I cant understand

`````

local function Move()
	...
end

	function move.Start(use) -- error
	...
	end
end

You have move.Start() INSIDE of Move() (The local function). That’s why its giving you nil for the function, because it cant actually find it, since it’s inside another one.
Just move it outside and you should be fine.

1 Like

they both are two different functions right one is Move() another one is move.Start I guess M and m makes difference

1 Like

Yes, but the move.Start function is inside of the Move() function, that’s what he’s trying to say, if you look at the end placements, you can see Move() doesn’t finish until the very bottom, before return move

1 Like

Oh, I didn’t notice that

1 Like

It’s fine, happens to us all, hopefuly OP sees this and manages to fix it :slight_smile:

2 Likes

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