Attempt to call a nil value

I have made a script where when you click a part, a GUI is cloned to a GUI in the PlayerGui of the player.

The problem is that I get the error: “attempt to call a nil value”.

How do I fix this error?

Script:

game.Players.PlayerAdded:Connect(function(plr)
	function onClick(click)
		local ItemGui = game.ReplicatedStorage.Gui:Clone()
		ItemGui.Frame.Name.Text = "Name"
		ItemGui.Frame.Price.Text = "Price"
		ItemGui.Frame.Description.Text = "Description"
		ItemGui.Parent = plr.PlayerGui.GuiHolder
	end
	end)

	script.Parent.ClickDetector.MouseClick:connect(onClick)

What line is this error occurring on? The output should provide a line number.

That’s the problem. it doesn’t provide a line number.

Im guessing its because ur trying to call something it cant reach. The function is inside another function

You are exactly right. @MoawesomeI8 You do not need the PlayerAdded function, and instead can use just the MouseClick. This is because the parameter click is automatically set to the player that clicks the detector.