Chat service glitch or something wrong with my code?

Basically, I am making a phone system where you can call other players.

Everything so far works, but when the player who chats second (2), sends the chat to the other player (1), it makes the other player (1) chat rather than the players phone, and it makes the second player’s (2) phone chat.

This also continues once the phone hangs up, when the second player (2) chats, the chat comes from their phone.

I’ve debugged both the local script and the server script to make sure that the right player is being seen as the reciever/sender, and there seems to be no other problem.

I’ve tried to use player.Chatted in a server script with playerAdded but there was a problem when checking the players value’s in the PlayerGui.

Finally, I tried switching between player.Character and workspace:FindFirstChild(). Didn’t change anything.

This is the server script:

local function SendMessage(sender, reciever, chat)
	print(reciever)
	local recieverChar = game.Workspace:FindFirstChild(reciever)
	if recieverChar and recieverChar:FindFirstChild("Phone") then
		local recievercharphone = recieverChar:FindFirstChild("Phone"):FindFirstChild("Handle")
		CS:Chat(recievercharphone, tostring(chat))
	end
end

RS.Remotes.SendMessage.OnServerEvent:Connect(SendMessage)

Local script:

Player.Chatted:Connect(function(chat)
	if Phone.Answered.Value == true and Phone.CallingPlayer.Value ~= "" then
		RS.Remotes.SendMessage:FireServer(Phone.CallingPlayer.Value, chat)
	end
end)

Example Video:

1 Like

Seems like local script is not fully described.

On the server side…

local function SendMessage(sender, reciever, chat)
	print(reciever)
	local recieverChar = reciever.Character--Replaced.
	if recieverChar and recieverChar:FindFirstChild("Phone") then
		local recievercharphone = recieverChar:FindFirstChild("Phone"):FindFirstChild("Handle")
		CS:Chat(recievercharphone, tostring(chat))
	end
end

RS.Remotes.SendMessage.OnServerEvent:Connect(SendMessage)

reciever is a string value, also .Character doesn’t change anything. I used it in the first place and just forgot to undo it when I was testing solutions.

Then, use player’s ID instead.
https://developer.roblox.com/en-us/api-reference/function/Players/GetPlayerByUserId