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

0

Maybe the bot's name isn't Npc or even existent

0

Bot's name is "Npc" that is the problem .-.

0

Does Npc exist? Does the humanoid of Npc exist? Does the NpcSpawnPart exist? Can we have a little bit more context

0

Im gonna check it again

0

Now the error is 17:28:12.098 - Workspace.Work.WorkScriptButtons:31: attempt to index a nil value

0

game.Workspace["Npc"].Head.Conversation.TextLabel.Text = "Woah you suck at this work..."

0

line 31^