Remote Event Delivering Nil Values but Succeeds

I had a previous post about the same system but a different bug. Now there’s a new issue popping up where a Remote Event fires but just gives me nil values.

Here is a screenshot:
Screen Shot 2020-06-25 at 12.48.03 PM

This is the QuestHandler script in ServerScriptService:

game.Players.PlayerAdded:Connect(function(player)
	local questStrings = {
        "The strings work like this";
		-- Different messages and stuff
	}
	
	local questRewards = {
        1; --This is just a sample
		-- Rewards that correspond with the former array
	}
	
	repeat wait() until player.QuestNum ~= nil

	while true do
		local currentQuestString = questStrings[player.QuestNum.Value]
		local currentQuestReward = questRewards[player.QuestNum.Value]
		game.ReplicatedStorage.DisplayQuest:FireClient(player, currentQuestString, currentQuestReward, player.QuestCompleted.Value)
		wait(0.1)
	end
end)

Here is my LocalScript. It finds the right labels and stuff fine, just it’s giving “nil” instead of the correct strings or values.

game.ReplicatedStorage.DisplayQuest.OnClientEvent:Connect(function(questString, questReward, questCompleted)
	script.Parent.CurrentQuestFrame.TextLabel.Text = tostring(questString)
	script.Parent.Button.TextLabel.Text = "Claim " .. tostring(questReward) .. " shards"
	script.Parent.Button.Active = questCompleted
	if questCompleted then
		script.Parent.Button.TextLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
	else
		script.Parent.Button.TextLabel.TextColor3 = Color3.fromRGB(150, 150, 150)
	end
end)

Please help me out, all help is appreciated.

There’s no values in questStrings or questRewards that match the key [player.QuestNum.Value], see how you built the table. If you printed out currentQuestString/Reward after indexing into the tables they would be nil.

Should be along the lines of:

local questStrings = {
    [PLAYERS_QUESTNUM_VALUE] = "content"
}

Also, with that infinite loop you got at the end there, you’ll be firing to the client a lot. I’m guessing it’s because you want to update their UI when their QuestNum value changes so it’ll reflect the right quest, but there are some cleaner ways to do it like a .Changed event.

I tried implementing your solution but it is still returning nil. Do you have any other ideas?

I tried using a print() statement to diagnose the issue, and what it’s doing is it works one time and returns nil all the other times. I let the statement run for a little bit to see what would happen, and this is what came in the output window:
Screen Shot 2020-06-25 at 1.52.35 PM

Did QuestNum.Value change after the first time? If so, that’s probably the culprit

Yeah, it went from 1 to 0. I’m not sure why because I don’t have any system in place to even change its value. The only thing I have for it is something that initially creates it.

I even used cmd + shift + f (I use a Mac) to see where QuestNum is referenced and all I saw was my initializer script and the QuestHandler one. I’m confused because I even looked thoroughly through those references and saw nothing that changes the value of it. (Obviously in the future I’ll put that system in, but I’m just taking it one step at a time.)