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
I have figured out the issue, but not a solution. The CFRAME does not return nil, it exists and has the numbers, but When the DICTIONARY is encoded, the CFrame value becomes null for what reason is unknown, and because of obvious reasons, when the JSON is decoded the CFrame value dissappears completely. Thus it is non-existant.
I am working out a solution right now.
Thanks I appreciate it alot for helping me
With reference to this post, youâd have to save each number indiviudually. Donât worry, I can sort that out for you.
oh so you are gonna make script for that ?
Yo do you know why game wonât work like everything is working fine but it shows only me in the game
This may take a while, solutions are hard to find.
I already made it save cframe but it wonât get info from other servers for some reasons
How did you get it to save CFrame, did you end up using position or saved each thing indiviudually?
nah I used thing that you said I saved them like this x = Part.CFrame.X y = Part.CFrame.Y and etc