Why Is This Not Firing The PlayerChatted Event?

Pretty simple question, when I use this script. The playerChatted function does not fire.

local teleportService = game:GetService("TeleportService")
local playerService = game:GetService("Players")
local messageService = game:GetService("MessagingService")
local remoteFunction = game.ReplicatedStorage.callSystem


messageService:SubscribeAsync("CallSystem", function(DataTable)
	local managers = {}
	for _, player in pairs(playerService:GetPlayers()) do
		if player:GetRankInGroup(32532119) >= 8 then
			local teleport = remoteFunction:InvokeClient(player, DataTable.Data.Username, DataTable.Data.DisplayName, DataTable.Data.helpMessage)
		end
	end
end)

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		local teleport = remoteFunction:InvokeClient(player)
		print(teleport)
	end)
end)

But if I put it above the SubscribeAsync function it does work.

local teleportService = game:GetService("TeleportService")
local playerService = game:GetService("Players")
local messageService = game:GetService("MessagingService")
local remoteFunction = game.ReplicatedStorage.callSystem


game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		local teleport = remoteFunction:InvokeClient(player)
		print(teleport)
	end)
end)

messageService:SubscribeAsync("CallSystem", function(DataTable)
	local managers = {}
	for _, player in pairs(playerService:GetPlayers()) do
		if player:GetRankInGroup(32532119) >= 8 then
			local teleport = remoteFunction:InvokeClient(player, DataTable.Data.Username, DataTable.Data.DisplayName, DataTable.Data.helpMessage)
		end
	end
end)

This actually does work.

1 Like

Any function that has Async means it will yield. It yields enough for the PlayerAdded event to connect right after you join the game.

So asyncs are always required to be put on the bottom of the script?

No, it requires an order and that depends on what the script does. Your order should be:

  1. PlayerAdded
  2. SubscribeAsync

that depends

its like doing

task.wait(5)
game.Players.PlayerAdded:Connect(funciton(plr)
       print(plr)
end)

.PlayerAdded wont fire because its blocked by task.wait

thats what you should look out for

look for functions that block other functions and then fix it

This code is vulnerable. An exploiter can infinitely yield the return of InvokeClient because the server asks the client for information. This will prevent any data being sent to clients after them.

You’re not using the RemoteFunction data here, have you considered using a RemoteEvent?

I don’t get it, why can exploiters use this remote function? And how should I do it if I do want to have the remoreFunction return something??

I don’t get it, why can exploiters use this remote function?

Basically; if an exploiter has a rank above 8 in the group and the remote function is fired for them, they can infinitely stall the response of the function which basically means the remote function won’t fire for any body else in that server.

All you have to do is replace the remote function with a remote event; same thing but it doesn’t require a return. Only use remote function if you need data returned from the client.

I probably didn’t explain it the best, you can refer to the docs for remote function for more information.

he doesnt even need to replace RemoteFunction with RemoteEvent

he can just do this to bypass the “halting” lol:

task.spawn(function()
        RemoteFunction:InvokeClient(player,data)
end)