I have problem when the player not in radius then its send this warn:
and when i do Properties.Text = nil its sends me a error: Unable to assign property Text. string expected, got nil
if string.lower(string.sub(Message.Text, 1, 3)) == "/me" then
local magnitude = (Player.Character:FindFirstChild("Head").Position - LocalPlayer.Character:FindFirstChild("Head").Position).magnitude
if magnitude < config.Radius then
Properties.Text ="<font color='#"..config.meColor.."'> "..string.sub(Message.Text, 5).."</font> "
else
Properties = {}
end
return Properties
end
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local config = require(script.Config)
TextChatService.OnIncomingMessage = function(Message: TextChatMessage)
local Properties = Instance.new("TextChatMessageProperties")
if Message.TextSource then
local Player = Players:GetPlayerByUserId(Message.TextSource.UserId)
if Player then
if Player.Character and Player.Character:FindFirstChild("Head") and LocalPlayer.Character then
if string.lower(string.sub(Message.Text, 1, 3)) == "/me" then
local magnitude = (Player.Character:FindFirstChild("Head").Position - LocalPlayer.Character:FindFirstChild("Head").Position).magnitude
if magnitude < config.Radius then
Properties.Text = "<font color='#"..config.meColor.."'> "..string.sub(Message.Text, 5).."</font> "
else
Properties = {}
end
return Properties
end
end
end
end
return Properties
end
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local config = require(script.Config)
TextChatService.OnIncomingMessage = function(Message: TextChatMessage)
local Properties = Instance.new("TextChatMessageProperties")
if Message.TextSource then
local Player = Players:GetPlayerByUserId(Message.TextSource.UserId)
if Player then
if Player.Character and Player.Character:FindFirstChild("Head") and LocalPlayer.Character then
if string.lower(string.sub(Message.Text, 1, 3)) == "/me" then
local magnitude = (Player.Character:FindFirstChild("Head").Position - LocalPlayer.Character:FindFirstChild("Head").Position).magnitude
if magnitude < config.Radius then
Properties.Text = "<font color='#"..config.meColor.."'> "..string.sub(Message.Text, 5).."</font>"
else
Properties.Text = ""
end
return Properties
end
end
end
end
return Properties
end
(if it works, please click the solution button on this post. thanks )
Okay so, by default this is going to create a remote event for you (but you can edit this if you want)
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ChatMessageEvent = Instance.new("RemoteEvent")
ChatMessageEvent.Name = "ChatMessageEvent"
ChatMessageEvent.Parent = ReplicatedStorage
local config = require(script.Config)
Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
local senderPosition = player.Character.HumanoidRootPart.Position
for _, recipient in ipairs(Players:GetPlayers()) do
if recipient.Character and recipient.Character:FindFirstChild("HumanoidRootPart") then
local recipientPosition = recipient.Character.HumanoidRootPart.Position
local distance = (recipientPosition - senderPosition).Magnitude
if distance <= config.Radius then
ChatMessageEvent:FireClient(recipient, player.Name, message)
else
ChatMessageEvent:FireClient(recipient, player.Name, "")
end
end
end
end
end)
end)
This will handle the range of the sender, and then each recipient will be checked if they are in the range. This is where the client script kicks in.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ChatMessageEvent = ReplicatedStorage:WaitForChild("ChatMessageEvent")
ChatMessageEvent.OnClientEvent:Connect(function(senderName, message)
local TextChatService = game:GetService("TextChatService")
if message == "" then
local Properties = Instance.new("TextChatMessageProperties")
Properties.Text = ""
TextChatService.OnIncomingMessage = function(Message)
return Properties
end
else
local Properties = Instance.new("TextChatMessageProperties")
Properties.Text = senderName .. ": " .. message
TextChatService.OnIncomingMessage = function(Message)
return Properties
end
end
end)
This will edit the message to either make it blank (invisible, Iβm pretty sure) or there.