Changing a ui from another localscript not working

I’m trying to make some sort of system where there (when activated) is a box around each player in the game apart from the localplayer, when this box is made it’s supposed to be able to be clicked by the localplayer and the name of that player would be put into the localplayer’s gui.

The thing is that when i’m clicking the part that’s on the player(s) character it doesnt print anything or work at all. I need some help with this.

Local Script (For the player doing it):

MainFrame.SelectionButton.MouseButton1Click:Connect(function()
	if MainFrame.SelectTxt.Text == "Select" then
		MainFrame.SelectTxt.TextColor3 = Color3.fromRGB(255, 175, 62)
		MainFrame.SelectTxt.Text = "Selecting"
		for i,v in pairs(game.Players:GetPlayers()) do
			if v.Name ~= plr.Name then
				local partThing = game:GetService("ReplicatedStorage").MCI.Model.MCI:Clone()
				partThing.Parent = v.Character
			end
		end
	else
		MainFrame.SelectTxt.TextColor3 = Color3.fromRGB(81, 109, 39)
		MainFrame.SelectTxt.Text = "Select"
		for i,v in pairs(game.Players:GetPlayers()) do
			if v.Name ~= plr.Name then
				v.Character.MCI:Destroy()
			end
		end
	end
end)

Local Script in the part:

local plr = game.Players.LocalPlayer
local gui = plr.PlayerGui.MciUi
local MainFrame = gui.MainFrame

script.Parent.MouseClick:Connect(function()
	local selectingPlayer = game.Players:GetPlayerFromCharacter(script.Parent.Parent.Parent.Parent)
	MainFrame.PlayerName.Text = selectingPlayer.Name
	MainFrame.SelectTxt.TextColor3 = Color3.fromRGB(109, 51, 51)
	MainFrame.SelectTxt.Text = "Unselect"
	for i,v in pairs(game.Players:GetPlayers()) do
		if v.Name ~= plr.Name then
			v.Character.MCI:Destroy()
		end
	end
end)

Please help, anything is apreciated. :smiley:

Assuming this part is in the workspace, there are multiple problems.

  1. Local scripts do not work within the workspace
  2. Parts do not have a MouseClick function.

The script’s parent is a ClickDetector, here is the setup for the part. These parts are copied into any other player than themselves. This is done through the first local script. So only the player can see the boxes. No one else.
image

Either way, LocalScripts do not work within workspace move the script into StarterGui and do it like this:

local ClickD = pathtoclickdetector
local plr = game.Players.LocalPlayer
local gui = plr.PlayerGui.MciUi
local MainFrame = gui.MainFrame

ClickD.MouseClick:Connect(function(selectingPlayer)
    MainFrame.PlayerName.Text = selectingPlayer.Name
	MainFrame.SelectTxt.TextColor3 = Color3.fromRGB(109, 51, 51)
	MainFrame.SelectTxt.Text = "Unselect"
	for i,v in pairs(game.Players:GetPlayers()) do
		if v.Name ~= plr.Name then
			v.Character.MCI:Destroy()
		end
	end
end)