Table finding key problem

So I made this script wich asks a module what kind of reward the player should get, i put some explaiining in the script. This is the serverscript.

for i,questCharacter in pairs(questCharactersFolder:GetChildren()) do -- quest character.Name = "Bob"
	questCharacter.ProximityPrompt.Triggered:Connect(function(player)
		local questNumber = table.find(questModule,questModule[questCharacter.Name]) -- quest number = nil

		askQuestRemote:FireClient(player,questNumber) -- quest number should be th index
	end)
end

This is the module

local quests = {
	["Bob"] = {
		name = "Neighbourhood Watch",
		text = "This was a beautiful neighborhood until all these bandits came, could you get rid of them for me?",
		enemy = {["Enemy"] = 5},
		reward = {["Xp"] = 25}
	}
}

return quests

And this is the local script:

askQuestRemote.OnClientEvent:Connect(function(questNumber)
	local questCharacter = questModule[questNumber]
	print(questCharacter,questNumber) -- prints nil,nil
	questNameText.Text = questModule[questNumber].name
	questText.Text = questModule[questNumber].text
	
	background.Visible = true
end)
1 Like

Dictionaries don’t store indexes (positions) of values, hence table.find() is unable to return a value. You will need to add a new variable inside of [“Bob”] that contains the quest number instead.

1 Like

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