Attempt to index function with 'Name'

  1. I want to fix an error I received called: ReplicatedStorage.Quests:16: attempt to index function with ‘Name’. I also want to understand why this error is occurring.

  2. The issue is that I have an error titled ReplicatedStorage.Quests:16: attempt to index function with ‘Name’, and I can’t find a solution to stop the error from occurring.

  3. I tried to find solutions on the DevForum and DevHub but my searches were futile.

local Quests = {

	["KillBandits"] = {
		["Name"] = "Kill 5 Bandits",
		["Goals"] = 5,
		["Exp"] = 50,
		["Gold"] = 50,
		["ID"] = "BanditsKilled"
	}

}

function Quests.FindQuest(plrChildren)	
	for i, v in pairs(plrChildren) do
		for quest, prop in pairs(Quests) do
			if prop.Name ==  v.Name then
				return quest
			elseif next(plrChildren, i) == nil then
				return false
			end
		end
	end
end

return Quests

please show us where you’re requiring that function[ findquest]

The error means that v is a function. What is plrChildren in this case?

2 Likes

plrChildren is a variable that equals player:GetChildren()

You think you could please print quest, prop, prop.Name and v.Name before the if statement?

1 Like

This is what I got

Quest:
KillBandits

prop:
table: 0xed66352428306288

prop.Name
Kill 5 Bandits

v.Name
PlayerScripts

1 Like
local rStorage = game:GetService("ReplicatedStorage")
local QE = rStorage.QuestEvent
local plr = game.Players.LocalPlayer
local quests = require(rStorage.Quests)
local QEN = rStorage.QuestEventNo


script.Parent.MouseButton1Click:Connect(function()
	--Get Quest Data
	local plrChildren = plr:GetChildren()
	local quest = quests.FindQuest(plrChildren)
	local id = quests[quest].ID
	local goals = quests[quest].Goals
	name = quests[quest].Name
	local exp = quests[quest].Exp
	local gold = quests[quest].Gold
	if plr.hasQuest.Value == false then
		local plrChildren = plr:GetChildren()
		for i, v in pairs(plrChildren) do
			if v.Name == name then
				QE:FireServer(goals, name, exp, gold, id)
			end
		end
	end
end)


--Closes Quest
script.Parent.Parent.npcQuestNo.MouseButton1Click:Connect(function()
	QEN:FireServer()
	local plrChildren = plr:GetChildren()
	for i, v in pairs(plrChildren) do
		if v.Name == name then
			v:Destroy()
		end
	end
end)





1 Like

I’m gonna get the Module Script and do some tests in studio, I think I might have found the issue.

I found it. For some reason, after the first time the script is run, it thinks prop.Name is a function. I’ll keep you updated.

1 Like

I also tried changing Name to name, but I received the same error. I also changed the prop variable to a different name, and I still got the same error.

local Quests = {

	["KillBandits"] = {
		["Name"] = "Kill 5 Bandits",
		["Goals"] = 5,
		["Exp"] = 50,
		["Gold"] = 50,
		["ID"] = "BanditsKilled"
	}

}

function Quests.FindQuest(plrChildren)	
	for i, v in pairs(plrChildren) do
		for quest, prop in pairs(Quests) do
			print(i)
			print(v)
			print(quest)
			print(prop)
			if typeof(prop) == "function" then continue end
			print(prop.Name)
			print("----------")
			if prop.Name == v.Name then
				return quest
			end
		end
	end
	return false
end

return Quests

(you can remove the prints or keep them if you’d like to test it for yourself, i added them just to do a quick test)

I was able to fix the issue. What was happening is because both the “KillBandits” dictionary and the FindQuest function are inside of the Quests table. I fixed it with a simple typeof to check if prop is a function, and if it is then continue the in pairs loop.

1 Like

Thanks for your response. It works now and the error is gone!

1 Like

No problems, glad I could help! If you need anything else, just mention me and i’ll check it for you.

2 Likes