Proximity chat script is not working

My script isn’t working. Does anyone know why? No errors are submitted.
The script makes the client see other player’s text more transparent based on how far away they are from one another.

game.Players.PlayerAdded:Connect(function(plr)--Server script to go in serverscriptservice, detects whoever sent the latest message in the chat
	plr.Chatted:Connect(function(msg)
		game.ReplicatedStorage.RadioEvent:FireAllClients(msg, plr)
	end)
end)
local chatframe = game.Players.LocalPlayer.PlayerGui:WaitForChild("Chat").Frame.ChatChannelParentFrame.Frame_
--chatframe is the scrolling frame that logs the text messages.
MessageLogDisplay.Scroller
local localplayer = game.Players.LocalPlayer
local maxDistance = 600 --Amount of studs before the text becomes fully transparent

game.ReplicatedStorage.RadioEvent.OnClientEvent:Connect(function(msg, player)
	chatframe.ChildAdded:Connect(function(child)--If a new text label is added then
		if child.TextLabel.Text == msg and player.Name ~= localplayer.Name then--If the text is from the new child's label, as well as the player name that sent the server message ISN'T the local player.
			print(player.Name)
			print(msg)
			local senderPos = player.Character.Head.Position
			local playerPos = localplayer.Character.Head.Position
			local distance = (senderPos - playerPos).Magnitude
			child.TextLabel.TextTransparency = distance / maxDistance
			child.TextLabel.TextButton.TextTransparency = distance / maxDistance
		end
	end)
end)

Does anyone know why it isn’t working?

2 Likes