-
What is the issue? Messaging Service is not getting anything when I use subscribeasync
print("Script Started v1.0.0a")
local MessagingService = game:GetService("MessagingService")
local TextService = game:GetService("TextService")
CreateNewPlayer = function(player,position)
print(player,position)
if typeof(player) == "string" then
local Model = Instance.new("Model")
Model.Parent = game.Workspace
Model.Name = player
local Part = Instance.new("Part")
Part.Parent = Model
Part.Position = position
Part.Anchored = true
Part.CanCollide = false
Part.Name = "Head"
local Humanoid = Instance.new("Humanoid")
Humanoid.Parent = Model
end
end
AddAMessageToPlayer = function(player,message,playerid)
if typeof(player) == "string" then
if game.Workspace:FindFirstChild(player) then
local filteredmessage = TextService:FilterStringAsync(message, playerid,Enum.TextFilterContext.PublicChat):GetNonChatStringForBroadcastAsync()
game.ReplicatedStorage.ClientHandler:FireAllClients(player,filteredmessage)
end
end
end
UpdatePosition = function(player,position)
if typeof(player) == "string" then
if game.Workspace:FindFirstChild(player) then
game.Workspace[player].Head.Position = position
end
end
end
RemovePlayer = function(player)
if typeof(player) == "string" then
if game.Workspace:FindFirstChild(player) then
game.Workspace[player]:Destroy()
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAppearanceLoaded:Wait()
local Position = player.Character.PrimaryPart.Position
local Playername = tostring(player.Name)
CreateNewPlayer(Playername)
MessagingService:PublishAsync("Multiplayer",Playername,Vector3.new(0, 0.5, 0))
player.Chatted:Connect(function(message)
AddAMessageToPlayer(player.Name,message,player.UserId)
pcall(function()
MessagingService:PublishAsync("MultiplayerChat",Playername,message,player.UserId)
end)
end)
spawn(function()
while true do
local humanoid = player.Character:WaitForChild("Humanoid")
if humanoid.MoveDirection ~= Vector3.new(0,0,0) then -- as you can see it's scuff since I didn't know what I was doing much back then
pcall(function()
UpdatePosition(Playername,player.Character.PrimaryPart.Position)
MessagingService:PublishAsync("UpdatePlayer",Playername,player.Character.PrimaryPart.Position)
end)
end
wait(0.5)
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
MessagingService:PublishAsync("RemoveMultiPlayer",player)
end)
MessagingService:SubscribeAsync("Multiplayer",function(player,position)
print(player,position)
CreateNewPlayer(player,position)
end)
MessagingService:SubscribeAsync("RemoveMultiPlayer",function(player)
RemovePlayer(player)
end)
MessagingService:SubscribeAsync("MultiplayerChat",function(player,message,playerid)
AddAMessageToPlayer(player,message,playerid)
end)
MessagingService:SubscribeAsync("UpdatePlayer",function(player,position)
UpdatePosition(player,position)
end)
1 Like
Try putting the components you send into messagingservice into a dictionary (only one extra can be sent with publishasync), I think I have had this issue before.
So for example;
{ [“PlayerName”] = “string”, [“PrimaryPartPosition”] = vector3}
Let me know if changing them all to a table works.
Reference them with info[“PlayerName”] or info[“PrimaryPartPosition”].
REPLACE ALL “ WITH KEYBOARD ORIGIN “, ALL QUOTATION MARKS ARE MOBILE UNICODES AND ARE NOT ACCEPTED BY ROBLOX
MessagingService:PublishAsync(): Cannot publish Dictionary, can only accept valid UTF-8 characters.
The “ are mobile unicodes, I am on mobile. Replace all of the “ with a normal “ from your keyboard. Sorry about that.
I did that already still didn’t worked says same thing
Paste the code here, I can have a look to see whats causing the problem.
local PositionTable = {['PlayerName'] = Playername, ['PrimaryPartPosition'] = Position}
CreateNewPlayer(PositionTable)
MessagingService:PublishAsync("Multiplayer",PositionTable)
I’ll hop on PC and check out the issue. Ill reply with a fix soon.
Thanks I would appreciate that
and I forgot to mention script subscribeasync first argument is a table for some reasons even tho it must be a player name
Make sure its only function(info
and not with the two arguments player,position
.
Then you can do
print(info["PlayerName"], info["PrimaryPartPosition"])
CreateNewPlayer(info["PlayerName"], info["PrimaryPartPosition"])
yes but how im gonna publish async with that table
local PositionTable = {['PlayerName'] = Playername, ['PrimaryPartPosition'] = Position}
CreateNewPlayer(PositionTable)
MessagingService:PublishAsync("Multiplayer",PositionTable)
The exact way you did it.
Just replace all multi-argument publishAsyncs into a table with all of the information, and publish that table, where it can be accessed.
it says that I can’t publish a dictionary
Ah. I’ll find a solution for that.
Thanks for helping me I appreciate it
With credit to this thread, what you should do is HttpService:JSONEncode(data goes here) the dictionary and send it encoded, then decode it with HttpService:JSONDecode(data goes here) inside the subscribeasync (set the decoded version inside a variable for easy access) and access its parts the same way.
1 Like
so I jsonencode table and then jsondecode it?
Yes, so when you publish it inside the :PublishAsync() at the position table value just wrap it in game:GetService(“HttpService”):JSONEncode(positionTable) (REPLACE “ SINCE MOBILE UNICODE) then inside the subscribeasync variable do local decodedInfo = game:GetService(“HttpService”):JSONDecode(info)
1 Like
Thanks for helping me I appreciate it
1 Like