Error:

ServerScriptService.Monitos:30: attempt to index local 'plrTouch' (a nil value)

Code:

local Monitors = workspace.Monitors
local Gui = script.MonitorGui
local Ex = Gui.Example


function DeleteAllButtons(gui)
	for _, v in pairs(gui:GetChildren()) do
		if v:IsA("TextButton") then
			if v.Name ~= Ex.Name then
				v:Destroy()
			end
		end
	end
end

function UpdateAllMonitors()
	for _, monitor in pairs(Monitors:GetChildren()) do
		local monitorPart = monitor.Monitor
		monitorPart:ClearAllChildren()
		local clone = Gui:Clone()
		clone.Parent = monitorPart
		-- And click function
		for _, v in pairs(clone:GetChildren()) do
			print(v.Name)
			if v:IsA("TextButton") then
				if v.Name ~= Ex.Name then
					v.MouseButton1Click:connect(function(plrTouch)
						if game.Players:FindFirstChild(v.Text) then
							local plrButton = game.Players:FindFirstChild(v.Text)
							if ((plrTouch.Character33.LocalPlayer.Name)-plrButton.Character).magnitude <= 16 then
								print("??!")
							end
						end
					end)
				end
			end
		end
	end
end

function UpdateGui()
	DeleteAllButtons(Gui)
	for _, plr in pairs(game.Players:GetChildren()) do
		local clone = Ex:Clone()
		clone.Parent = Gui
		clone.Visible = true
		clone.Name = plr.Name
		clone.Text = plr.Name
	end
	
	UpdateAllMonitors()
end

game.Players.ChildAdded:connect(UpdateGui)

5 comments

0

MouseButton1Click doesn't pass any arguments, therefor plrTouch is nil

0

What I needed to change?

0

Did you make this script?

0

No. My friend he's don't know how to fix this error. And I'm suggest him to post question. He's agree it.

0

Do this code isn’t yours? Moderated for not constructive!