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:
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.
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 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:
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.)