Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do i remove this error? keeps popping up...

Asked by 6 years ago

the script works just fine, but i would lie to remove this error because it clogs up my output window.

the error is: Workspace.Buildings.WorkPlace_1.Floor_4.NPCs.Mark.QUEST03:33: attempt to index local 'Player' (a nil value)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local QuestLibraries    = ReplicatedStorage:FindFirstChild("QuestService")

-- Libraries --
local Dialogs = require(QuestLibraries:FindFirstChild("Dialogs"))
local Quests  = require(QuestLibraries:FindFirstChild("Quests"))

-- Variables --
local QuestGUI = ReplicatedStorage:FindFirstChild("QUEST03_Dialog", true)
local Quest    = script.Configurations.Quest.Value
local Enabled  = script.Configurations.Enabled.Value

-- Create Quest Folder Function -- 
function StartQuest(QuestID)
    local folder = Instance.new("Folder")
    folder.Name = QuestID

    local number = Instance.new("IntValue")
    number.Name = "Number"
    number.Parent = folder

    return folder
end




script.Parent.Toutch.Touched:connect(function(part) -- When the player toutched the part called "Toutch"

    if part.Parent:FindFirstChild("Humanoid") ~= nil then

        local Player    = game.Players:FindFirstChild(part.Parent.Name)
        local PlayerGui = Player:WaitForChild("PlayerGui")

        if PlayerGui:FindFirstChild("QUEST03_Dialog") == nil then

            ----- GUI Parts -----
            local GUI         = QuestGUI:Clone()
            local Main        = GUI.Hold.Frame
            local GUI_Name    = Main:FindFirstChild("Name")
            local Decline_Btn = Main:FindFirstChild("Decline")
            local Accept_Btn  = Main:FindFirstChild("Accept")
            local NPC_Dialog  = Main:FindFirstChild("Desc1")

            ---- Quest/Dialog Tables ----
            local Dialog_Data = Dialogs.dialog[Quest]
            local Quest_Data  = Quests.quests[Quest]

            ---- Set Defaults ----
            GUI_Name.Text    = " "..script.Parent.Name
            Decline_Btn.Text = Dialog_Data["NoQuest"]["EXIT"]

            GUI.Parent       = PlayerGui -- Put gui into player


            ---- Get number of Dialogs ----
            local num_of_dialogs = 0

            for key,value in pairs(Dialog_Data["NoQuest"]) do
                if key ~= "EXIT" then
                    num_of_dialogs = num_of_dialogs + 0.5
                end
            end

            ---- Go through Dialogs ----
            local onQuest    = false
            local isComplete = false    
            local dialog_num = 1        
            local Quest_Folder = nil
            if Player:FindFirstChild(Quest) ~= nil then
                 Quest_Folder = Player:FindFirstChild(Quest)

                onQuest = true

                if Quest_Folder.Number.Value >= 1 then
                    isComplete = true
                end
            end         

            if onQuest then

                    Accept_Btn.Visible = false

                    if isComplete then
                        NPC_Dialog.Text    = " "..Dialog_Data["Quest"]["COMPLETE"]
                        Decline_Btn.Text   = "Yay!"

                        ---- completion and rewards ----
                        Quest_Folder:Destroy()

                        local leaderstats = Player:FindFirstChild("leaderstats")
                        local Money = leaderstats:FindFirstChild("Money")

                        Money.Value = Money.Value + Quest_Data["Cash"]

                        local Coffee = Player.Backpack:FindFirstChild("Pen")

                        Coffee:Destroy()


                    else
                        NPC_Dialog.Text    = " "..Dialog_Data["Quest"]["INCOMPLETE"]
                        Decline_Btn.Text   = "Oh my bad"
                    end

                    else

                    Accept_Btn.MouseButton1Click:connect(function()

                    if dialog_num ~= num_of_dialogs then
                        dialog_num = dialog_num + 1

                        NPC_Dialog.Text = Dialog_Data["NoQuest"]["NPC"..dialog_num]
                        Accept_Btn.Text = Dialog_Data["NoQuest"]["RES"..dialog_num]
                    else
                        local Quest_Folder = StartQuest(Quest)
                        Quest_Folder.Parent = Player
                        GUI:Destroy()
                end 

        end)
    end
end







    end

end)


how do i solve the error? i have tried many things but cannot get it to go away.

3 answers

Log in to vote
0
Answered by 6 years ago

If it ain't broken, don't fix it.

0
but its clogging up my output which i would like to get rid of so i can focus my time on fixing script errors and not having to find them inside of those errors. Creeper_Dude158 11 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Try changing the Variable name from Player to something else (Example: "plr", "dude", etc). I've had this error before aswell, and ROBLOX recognizes Player as a global variable, not a local one.

Hope this helps!

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
local Player = game.Players:FindFirstChild(part.Parent.Name)
if not Player then
    return
end

So it looks for the player in Players. If it dosen't find the player then it uses return to end the execution. Else, it finds the player and continues the code.

Answer this question