Hello!
I have made a local script where it makes quests for the player to do in return for Credits and XP.
The problem is that on one line where it checks if the player is holding the item it spits out this error:
17:56:12.411 Argument 1 missing or nil - Client - QuestHandler:157
This is the Error line: ItemQuest is the nil part.
if player.Character:FindFirstChild(ItemQuest) then
However the code still runs in that and it does work but I don’t know why ItemQuest is nil.
Local script:
local player = game.Players.LocalPlayer
-- Workspace
local QuestNPC = workspace.OminusOfficesMap.QuestNPC["Suspicious Simon"]
local ProxPrompt = QuestNPC:WaitForChild("Torso").ProximityPrompt
-- Sounds
local ClickSound = game:GetService("SoundService").Click
--- UI ---
-- QuestGUI
local ScreenGUI = script.Parent
local QuestFrame = ScreenGUI.QuestFrame
local MainFrame = ScreenGUI.MainFrame
local NameFrame = ScreenGUI.NameFrame
local GoodsFrame = ScreenGUI.GoodsFrame
-- Inside Main Frame
local NeverMindBTN = MainFrame.NeverMind
local QuestBTN = MainFrame.QuestBTN
local HowNameBTN = MainFrame.HowName
local MainText = MainFrame:FindFirstChild("1Text")
local MainTextBack = MainFrame:FindFirstChild("1TextBack")
-- Inside Quest Frame
local ThanksBTN = QuestFrame.Thanks
local QuestText = QuestFrame:FindFirstChild("1Text")
local QuestTextBack = QuestFrame:FindFirstChild("1TextBack")
-- Inside Name Frame
local WierdoBTN = NameFrame.Wierdo
local NameText = NameFrame:FindFirstChild("1Text")
local NameTextBack = NameFrame:FindFirstChild("1TextBack")
-- Inside Goods Frame
local GotBTN = GoodsFrame.GotitBtn
local GoodsText = GoodsFrame:FindFirstChild("1Text")
local GoodsTextBack = GoodsFrame:FindFirstChild("1TextBack")
local WelcomeBTN = GoodsFrame.WelcomeBTN
-- ObjectivesGUI
local ObjectivesGUI = script.Parent.Parent.ObjectiveGUI
local ObjectivesMainFrame = ObjectivesGUI.MainFrame
local TaskFrame = ObjectivesMainFrame.TaskFrame
local TaskText = TaskFrame.Task
local ObjectivesText = ObjectivesMainFrame.Objectives
local TutEnabledBTN = ObjectivesGUI.TutEnabled
-- PlayerStatsUI
local PSUI = script.Parent.Parent.PlayerStats
local AddCreditsText = PSUI.AddCredits
local AddXPText = PSUI.AddXP
-- REMOTES --
local ServerSellingRemote = game:GetService("ReplicatedStorage").Remotes.ServerSelling
local XPRemote = game:GetService("ReplicatedStorage").Remotes.XP
-- CODE --
local Quests = {
{Task = "Give a Newspaper to Simon", Credits = 10, XP = 50, Quest = "I'm bored, will ya fetch me a newspaper?", Item = "Newspaper"},
{Task = "Give a Rat to Simon", Credits = 7, XP = 35, Quest = "Rats are mighty delicious, can you fish me out one?", Item = "Rat"},
{Task = "Give a Desk to Simon", Credits = 165, XP = 500, Quest = "I need a new desk, Can you go and get me a Desk?", Item = "Desk"},
{Task = "Give a SMART Desk to Simon", Credits = 435, XP = 2500, Quest = "I heard that the SMART Desks are all the hype nowadays, It wouldn’t hurt to get one right???",Item = "SMART Desk" },
{Task = "Give a PC to Simon", Credits = 500, XP = 2300, Quest = "Do kids play on PCs now? Can you acquire one?", Item = "PC"},
{Task = "Give a Pot Plant to Simon", Credits = 15, XP = 30, Quest = "My desk is looking empty, a pot plant will help!", Item = "Pot Plant"},
{Task = "Give a Mug to Simon", Credits = 8, XP = 10, Quest = "I need a Mug to hold my Coffee!",Item = "Mug"},
{Task = "Give a Microwave to Simon", Credits = 300, XP = 1700, Quest = "My old Microwave is broken, can ya fetch me a new one?", Item = "Microwave"},
{Task = "Give a Printer to Simon", Credits = 150, XP = 900, Quest = "I’m not allowed to use Printers at work anymore, can you go and get me one?",Item = "Printer"},
{Task = "Give a Paint Can to Simon", Credits = 10, XP = 25, Quest = "I need to repaint my fence, can you buy some Paint?", Item = "Paint Can"},
}
ProxPrompt.Triggered:Connect(function()
ClickSound:Play()
ProxPrompt.Enabled = false
ScreenGUI.Enabled = true
local part = QuestNPC.DialoguePart
local camera = workspace.CurrentCamera
local worldPoint = part.Position
local vector = camera:WorldToScreenPoint(worldPoint)
local screenPoint = UDim2.new(0, vector.X, 0, vector.Y)
local depth = vector.Z
MainFrame.Position = screenPoint
QuestFrame.Position = screenPoint
NameFrame.Position = screenPoint
----------------- CODE ------------------------
MainText.Text = "Hello, Planey..."
MainTextBack.Text = "Hello Planey..."
NeverMindBTN.MouseButton1Click:Connect(function()
ClickSound:Play()
ScreenGUI.Enabled = false
ProxPrompt.Enabled = true
end)
local ItemQuest = nil
local CreditsQuest = nil
local XPQuest = nil
QuestBTN.MouseButton1Click:Connect(function()
QuestFrame.Visible = true
MainFrame.Visible = false
ClickSound:Play()
local RandomQuestNum = math.random(1,10)
local Quest = Quests[RandomQuestNum]
print("Quest: "..Quest.Task)
QuestText.Text = Quest.Quest
QuestTextBack.Text = Quest.Quest
ObjectivesGUI.Enabled = true
ObjectivesText.Text = "Quests"
TaskText.Text = Quest.Task
ObjectivesMainFrame.Visible = true
TutEnabledBTN.Visible = false
ItemQuest = Quest.Item
CreditsQuest = Quest.Credits
XPQuest = Quest.XP
end)
ThanksBTN.MouseButton1Click:Connect(function()
ClickSound:Play()
MainFrame.Visible = true
QuestFrame.Visible = false
ScreenGUI.Enabled = false
ProxPrompt.Enabled = true
end)
for i, item in ipairs(Quests) do
if TaskText.Text == item.Task then
MainFrame.Visible = false
GoodsFrame.Visible = true
end
end
GotBTN.MouseButton1Click:Connect(function()
ClickSound:Play()
if ItemQuest ~= nil then
print(ItemQuest)
end
if player.Character:FindFirstChild(ItemQuest) then -- The Error Line
local HeldPart = player.Character:FindFirstChild(ItemQuest)
print("Recieved Quest")
GoodsText.Text = "Thanks"
GoodsTextBack.Text = "Thanks"
GotBTN.Visible = false
WelcomeBTN.Visible = true
if CreditsQuest and XPQuest ~= nil then
ServerSellingRemote:FireServer(CreditsQuest)
XPRemote:FireServer(XPQuest)
print("Gave player Credits and XP for completing Quest")
AddCreditsText.Text = "+ ".. CreditsQuest
AddXPText.Text = "+ ".. XPQuest.."XP"
HeldPart:Destroy()
ObjectivesGUI.Enabled = false
MainFrame.Visible = false
CreditsQuest = nil
XPQuest = nil
AddCreditsText.Visible = true
AddXPText.Visible = true
wait(5)
AddCreditsText.Visible = false
AddXPText.Visible = false
end
else
print("Player does not have required Item.")
end
WelcomeBTN.MouseButton1Click:Connect(function()
ClickSound:Play()
GoodsFrame.Visible = false
MainFrame.Visible = true
WelcomeBTN.Visible = false
GotBTN.Visible = true
end)
end)
end)