I have this LocalScript that checks if the player has completed a quest, and if completed, it fires a remote event. I tried to make my code more efficient and clean, however it does not work.
This is the code before (works)
local RepStor = game:GetService("ReplicatedStorage")
local QuestEventFolder = RepStor:WaitForChild("Quests")
local QuestFolder = QuestEventFolder:WaitForChild("BasicBH")
local Q1 = QuestFolder:WaitForChild("Quest1")
local QC = QuestFolder:WaitForChild("QuestComplete")
local Player = game.Players.LocalPlayer
local BasicBHQuestFolder = Player:WaitForChild("BasicBHQuest")
local Started = BasicBHQuestFolder:WaitForChild("Started")
local NormalPotato = BasicBHQuestFolder:WaitForChild("NormalPotato")
local NormalPotatoNeeded = BasicBHQuestFolder:WaitForChild("NormalPotatoNeeded")
local SoftPotato = BasicBHQuestFolder:WaitForChild("SoftPotato")
local SoftPotatoNeeded = BasicBHQuestFolder:WaitForChild("SoftPotatoNeeded")
local SweetPotato = BasicBHQuestFolder:WaitForChild("SweetPotato")
local SweetPotatoNeeded = BasicBHQuestFolder:WaitForChild("SweetPotatoNeeded")
local TotalPotato = BasicBHQuestFolder:WaitForChild("TotalPotato")
local TotalPotatoNeeded = BasicBHQuestFolder:WaitForChild("TotalPotatoNeeded")
local Completed = BasicBHQuestFolder:WaitForChild("Completed")
NormalPotato.Changed:Connect(function()
if NormalPotatoNeeded.Value ~= 0 and Started.Value then
if NormalPotato.Value >= NormalPotatoNeeded.Value and
SoftPotato.Value >= SoftPotatoNeeded.Value and
SweetPotato.Value >= SweetPotatoNeeded.Value and
TotalPotato.Value >= TotalPotatoNeeded.Value then
QC:FireServer()
end
end
end)
SoftPotato.Changed:Connect(function()
if SoftPotatoNeeded.Value ~= 0 and Started.Value ~= false then
if SoftPotato.Value >= SoftPotatoNeeded.Value and
NormalPotato.Value >= NormalPotatoNeeded.Value and
SweetPotato.Value >= SweetPotatoNeeded.Value and
TotalPotato.Value >= TotalPotatoNeeded.Value then
QC:FireServer()
end
end
end)
SweetPotato.Changed:Connect(function()
if SweetPotatoNeeded.Value ~= 0 and Started.Value ~= false then
if SweetPotato.Value >= SweetPotatoNeeded.Value and
SoftPotato.Value >= SoftPotatoNeeded.Value and
NormalPotato.Value >= NormalPotatoNeeded.Value and
TotalPotato.Value >= TotalPotatoNeeded.Value then
QC:FireServer()
end
end
end)
TotalPotato.Changed:Connect(function()
if TotalPotatoNeeded.Value ~= 0 and Started.Value ~= false then
if TotalPotato.Value >= TotalPotatoNeeded.Value and
SoftPotato.Value >= SoftPotatoNeeded.Value and
SweetPotato.Value >= SweetPotatoNeeded.Value and
NormalPotato.Value >= NormalPotatoNeeded.Value then
QC:FireServer()
end
end
end)
The code when improved (does not work, the variables remain the same):
local function CheckQuest()
if Started.Value and
NormalPotato.Value >= NormalPotatoNeeded.Value and
SoftPotato.Value >= SoftPotatoNeeded.Value and
SweetPotato.Value >= SweetPotatoNeeded.Value and
TotalPotato.Value >= TotalPotatoNeeded.Value then
QC:FireServer()
end
end
NormalPotato.Changed:Connect(CheckQuest)
SoftPotato.Changed:Connect(CheckQuest)
SweetPotato.Changed:Connect(CheckQuest)
TotalPotato.Changed:Connect(CheckQuest)
The 2 peices of code above look the same to me, so I have no idea why the improved version doesn’t work.