I am making basic Work gui. Player who is working is chosing Bot's order. But when player click a part with Click detector, it print me this error:
17:28:12.098 - Workspace.Work.WorkScriptButtons:33: attempt to index a nil value
The script (Normal script) looks like this:
local ClickDetector1 = script.Parent:WaitForChild("Burger").ClickDetector
local ClickDetector2 = script.Parent:WaitForChild("Cola").ClickDetector
local OrderValue = script.Parent:WaitForChild("Order")
ClickDetector1.MouseClick:Connect(function()
if OrderValue.Value == "Burger" then
script.Parent.Earning.Value = script.Parent.Earning.Value + 15
game.Workspace:FindFirstChild("Npc").Head.Conversation.TextLabel.Text = "Thanks!"
wait(1)
game.Workspace:FindFirstChild("Npc").Humanoid:MoveTo(game.Workspace.Work.NpcSpawnPart.Position)
wait(1)
game.Workspace:FindFirstChild("Npc"):Destroy()
else
game.Workspace:FindFirstChild("Npc").Head.Conversation.TextLabel.Text = "Woah you suck at this work..."
wait(1)
game.Workspace:FindFirstChild("Npc").Humanoid:MoveTo(game.Workspace.Work.NpcSpawnPart.Position)
wait(1)
game.Workspace:FindFirstChild("Npc"):Destroy()
end
end)
ClickDetector2.MouseClick:Connect(function()
if OrderValue.Value == "Cola" then
script.Parent.Earning.Value = script.Parent.Earning.Value + 15
game.Workspace:FindFirstChild("Npc").Head.Conversation.TextLabel.Text = "Thanks!"
wait(1)
game.Workspace:FindFirstChild("Npc").Humanoid:MoveTo(game.Workspace.Work.NpcSpawnPart.Position)
wait(1)
game.Workspace:FindFirstChild("Npc"):Destroy()
else
game.Workspace:FindFirstChild("Npc").Head.Conversation.TextLabel.Text = "Woah you suck at this work..."
wait(1)
game.Workspace:FindFirstChild("Npc").Humanoid:MoveTo(game.Workspace.Work.NpcSpawnPart.Position)
wait(1)
game.Workspace:FindFirstChild("Npc"):Destroy()
end
end)
Can someone help?

7 comments
Maybe the bot's name isn't Npc or even existent
Bot's name is "Npc" that is the problem .-.
Does Npc exist? Does the humanoid of Npc exist? Does the NpcSpawnPart exist? Can we have a little bit more context
Im gonna check it again
Now the error is 17:28:12.098 - Workspace.Work.WorkScriptButtons:31: attempt to index a nil value
game.Workspace["Npc"].Head.Conversation.TextLabel.Text = "Woah you suck at this work..."
line 31^