Attempt to index function with 'Name' - Server

Error Log:

 ▶ {...}  -  Server - Script:3
  16:21:24.977  ReplicatedStorage.Quests:23: attempt to index function with 'Name'  -  Server - Quests:23
  16:21:24.977  Stack Begin  -  Studio
  16:21:24.977  Script 'ReplicatedStorage.Quests', Line 23 - function CompleteQuest  -  Studio - Quests:23
  16:21:24.977  Script 'ServerScriptService.Script', Line 4  -  Studio - Script:4
  16:21:24.977  Stack End  -  Studio
  19:04:58.309  Disconnect from ::ffff:127.0.0.1|57879  -  Studio

I can print the Quest Info with a function, but when I try to change Quest Info with another function, it errors.
Heres my module “Quests”:

local Quests = {
	[1] = {
		Name = "One Step Forward",
		Requirements = {{"Join", 1},{"CollectApple", 1}},
		Rewards = {
			["ItemApple"] = 5,
			["Money"] = 100
		},
		Progress = 0
	}
}

function Quests:GetQuestData(Quest)
	for i, v in pairs(Quests) do
		if v["Name"] == Quest then
			return v
		end
	end
end

function Quests:CompleteQuest(Quest)
	for i, v in pairs(Quests) do
		if v["Name"] == Quest then
			v["Progress"] = 100
			local Apples = table.find(v["Rewards"], "ItemApple")
			local Test = table.find(v["Rewards"], "Honey") -- Won't show up, which is good!
			if Apples == "ItemApple" then
				print("Item Rewarded")
			end
			if Test == "Honey" then
				print("honeYYY")
			end
		end
	end
end

return Quests

Heres how I fire the Module:

local Module = require(game.ReplicatedStorage.Quests)
local QuestData = Module:GetQuestData("One Step Forward")
print(QuestData)
Module:CompleteQuest("One Step Forward")

I use a server script and I’ve tried 6 solutions and nothing has worked out for me.

You keep your functions in the same place as your data so when you iterate over Quests, v is sometimes a function.
Make a separate table instead of reusing Quests. You can put it inside Quests if you want. Maybe call it Quests.Active or something like that.

This just gave me a better idea, I’ll most likely just put it in 1 function and make it a BoolValue, like:

function Quests:ChangeQuest(QuestName, GetData, CompleteQuest)
    if GetData then
       return Code
    elseif CompleteQuest then
        -- a
    end
end

Thanks for your help!

1 Like

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