I’m trying to create a quest system but I keep getting on this error within my main script. This script includes Remote events, distance/magnitude, and Datastore2 which comes with a inventory system built alongside it. I can’t seem to resolve the warning myself with debugging it as I don’t seem to understand the enchanced watch windows in most proper way possible.
If anyone can try and resolve this warning/ yield error, that would be great. Here’s the warning that I recieve:
Infinite yield possible on 'ServerStorage:WaitForChild("DataStore2")' - Studio
10:40:16.650 Stack Begin - Studio
10:40:16.650 Script 'Players.Dev_Frags.PlayerGui.QuestGUI.MainScript', Line 3 - Studio - MainScript:3
10:40:16.650 Stack End
Here is the script down below…
local RS = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local DSS2 = require(ServerStorage:WaitForChild("DataStore2")) -- Where it yields and stops the script.
local Quest1Events = RS:WaitForChild("Quest1Events")
local questEvent = Quest1Events:WaitForChild("QuestActivated")
local collectEvent = Quest1Events:WaitForChild("collectEvent")
local returnEvent = Quest1Events:WaitForChild("returnEvent")
local blueBerry = game.ServerStorage:FindFirstChild("BlueBerry")
local QuestEnabled = Quest1Events:WaitForChild("QuestEnabled")
local finishedQuest = Quest1Events:WaitForChild("QuestFinished")
local player = game.Players.LocalPlayer
local playerGui = player:FindFirstChild("PlayerGui")
local RunService = game:GetService("RunService")
local gui = script.Parent
local MainFrame = gui.Frame
local descriptionText = MainFrame.Description
local collectPart2 = game.Workspace.collectPart2
local no = gui.Frame.No
local yes = gui.Frame.Yes
local clickhereFrame = gui.Frame.ClickAnywhere
local clickheretoContinue = gui.Frame.ClickAnywhere.ClickHereButton
local character = player.Character or player.CharacterAdded:Wait()
local dummy = game.Workspace.Dummy
local debounce = false
local distanceShow = character:WaitForChild("Head").Position.Magnitude - dummy.Head.Position.Magnitude -- DO LATER!!!
questEvent.OnClientEvent:Connect(function()
if player.hasQuest.Value == false then
game.ReplicatedStorage.Quest1Events.QuestEnabled:FireServer(player)
gui.Enabled = true
descriptionText.Text = "Hey, would you mind doing a favor for me?"
no.Visible = false
yes.Visible = false
clickhereFrame.Visible = true
clickheretoContinue.MouseButton1Click:Connect(function()
descriptionText.Text = "Would you mind collecting a Blueberry for me?"
clickhereFrame.Visible = false
no.Visible = true
yes.Visible = true
end)
wait(1)
yes.YesButton.MouseButton1Click:Connect(function()
descriptionText.Text = "Awesome! Go collect a blueberry and bring it back to me!"
clickhereFrame.Visible = true
yes.Visible = false
no.Visible = false
end)
no.NoButton.MouseButton1Click:Connect(function()
descriptionText.Text = "Goodbye then and have a great day... :("
wait(2)
gui.Enabled = false
player.hasQuest.Value = false
end)
player.hasQuest.Value = false
elseif player.hasQuest.Value == true then
gui.Enabled = true
descriptionText.Text = "You already have a quest! Finish this quest to start a another one!"
while wait(0.01) do
for i,v in pairs(game.Players:GetPlayers()) do
if distanceShow <= 5 then
descriptionText.Text = "You ended the discussion."
wait(2)
gui.Enabled = false
end
end
end
end
end)
collectEvent.OnClientEvent:Connect(function()
if player.Backpack:FindFirstChild("BlueBerry") then
descriptionText.Text = "You collected a Blueberry! Return to the dummy and touch him to get your reward!"
end
end)
collectPart2.Touched:Connect(function()
local BlueBerryName = blueBerry.Name
local InvStore = DSS2("Inventory", player)
InvStore:Update(function(currentTable)
if currentTable[BlueBerryName] then
currentTable[BlueBerryName] = currentTable[BlueBerryName] - 1
descriptionText.Text = "Thanks for the blueberry! Here's 25 coins as your reward!"
finishedQuest:FireServer(player)
clickhereFrame.Visible = false
wait(3.5)
yes.Visible = false
no.Visible = false
gui.Enabled = false
else
currentTable[BlueBerryName] = 1
print("Cannot find a BlueBerry!")
end
return currentTable
end)
end)
Thanks for reading and have a good day!