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.
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)
Thanks for helping me I appreciate it
I highly recommend using the task scheduler for this it would improve your code alot!
Hello now it won’t save position for some reason it saved playername but won’t save position
What line is the error on so I can check what the issue could be?
print("Script Started v2.0.0a")
local MessagingService = game:GetService("MessagingService")
local HttpService = game:GetService("HttpService")
local TextService = game:GetService("TextService")
CreateNewPlayer = function(PositionTablee)
local PositionTable = HttpService:JSONDecode(PositionTablee)
if typeof(PositionTable) == "table" then
for i,v in pairs(PositionTable) do
print(i,v)
end
local Model = Instance.new("Model")
Model.Parent = game.Workspace
Model.Name = PositionTable['PlayerName']
local Part = Instance.new("Part")
Part.Parent = Model
Part.CFrame = PositionTable['CFrame'] -- Error Here Unable to assign property CFrame. CoordinateFrame expected, got nil
Part.Anchored = true
Part.CanCollide = false
Part.Name = "Head"
local Humanoid = Instance.new("Humanoid")
Humanoid.Parent = Model
end
end
AddAMessageToPlayer = function(encodedtable)
local decodedtable = HttpService:JSONDecode(encodedtable)
if typeof(decodedtable) == "table" then
if game.Workspace:FindFirstChild(decodedtable['PlayerName']) then
local filteredmessage = TextService:FilterStringAsync(decodedtable['Message'], decodedtable['PlayerId'],Enum.TextFilterContext.PublicChat):GetNonChatStringForBroadcastAsync()
game.ReplicatedStorage.ClientHandler:FireAllClients(decodedtable['PlayerName'],filteredmessage)
end
end
end
UpdatePosition = function(PositionTablee)
local UpdateTable = HttpService:JSONDecode(PositionTablee)
if typeof(UpdateTable) == "table" then
if game.Workspace:FindFirstChild(UpdateTable['PlayerName']) then
game.Workspace[UpdateTable['PlayerName']].Head.CFrame = UpdateTable['CFrame']
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 PositionTable = HttpService:JSONEncode({["PlayerName"] = player.Name,["CFrame"] = player.Character.HumanoidRootPart.CFrame})
CreateNewPlayer(PositionTable)
MessagingService:PublishAsync("Multiplayer",PositionTable)
player.Chatted:Connect(function(message)
local MessageTable = HttpService:JSONEncode({["PlayerName"] = player.Name,["Message"] = message,["PlayerId"] = player.UserId})
AddAMessageToPlayer(MessageTable)
pcall(function()
MessagingService:PublishAsync("MultiplayerChat",MessageTable)
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()
local PositionTable = HttpService:JSONEncode({["PlayerName"] = player.Name,["Position"] = player.Character.HumanoidRootPart.Position})
UpdatePosition(PositionTable)
MessagingService:PublishAsync("UpdatePlayer",PositionTable)
end)
end
wait(0.5)
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
MessagingService:PublishAsync("RemoveMultiPlayer",player.Name)
end)
MessagingService:SubscribeAsync("Multiplayer",function(PositionTable)
CreateNewPlayer(PositionTable)
end)
MessagingService:SubscribeAsync("RemoveMultiPlayer",function(player)
RemovePlayer(player)
end)
MessagingService:SubscribeAsync("MultiplayerChat",function(MessageTable)
AddAMessageToPlayer(MessageTable)
end)
MessagingService:SubscribeAsync("UpdatePlayer",function(PositionTable)
UpdatePosition(PositionTable)
end)
it gives only a player in table even tho it works fine for message thing
Are you sure you defined CFrame in the position table?
Ye I am sure you can check the script source
Add a :WaitForChild() for the humanoidrootpart.
:WaitForChild(“HumanoidRootPart”).CFrame
still errors and I already had a thing that waits till character loads
Just to clarify, is the error about Position or CFrame?
Unable to assign property CFrame. CoordinateFrame expected, got nil