Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Problem with global chat.(By global I do not mean global across all servers.) Any help? [Solved]

Sorry about the horrible title but I couldn't think of one that describes my problem.

I have this script that updates chat boards around the map. It checks if the player is within the global chat range and if not doesn't update the chat boards.

It works fine but once the player dies it updates the global boards no matter where they are. This also happens when their character is reloaded.

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(char)
		player.Chatted:connect(function(msg, recipient, plr)
			local micpos = workspace.StageMic.Handle.Position
			local charpos = char.Torso.Position
			if (micpos - charpos).magnitude <= 5 then
				for i,v in pairs(workspace.MessageBoardSystem:GetChildren()) do
					if v:IsA("Part") then
						if v:FindFirstChild("SurfaceGui") then
							v.SurfaceGui.TextBox.Text = player.Name..": "..msg
						end
					end
				end
			end
		end)	
	end)
end)


1 answer

I suspect that the problem is that you haven't disconnected the event once the player died. Try this out

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(char)
		local con1
		con1 = player.Chatted:connect(function(msg, recipient, plr)
			local micpos = workspace.StageMic.Handle.Position
			local charpos = char.Torso.Position
			if (micpos - charpos).magnitude <= 5 then
				for i,v in pairs(workspace.MessageBoardSystem:GetChildren()) do
					if v:IsA("Part") and v:FindFirstChild("SurfaceGui") then
						v.SurfaceGui.TextBox.Text = player.Name..": "..msg
					end
				end
			end
		end)   
		char.Humanoid.Died:connect(function()
			con1:disconnect()
		end)
	end)
end)

1 comment

0

Sorry I should have closed this question. I figured it out. The problem was, I was using a server script and should have used a local script.

This discussion is preserved as it was. New answers, comments, and votes are closed.