Help me with a script

Paste the whole code here (to stay up to date). I can’t figure out the issue.

print("Script Started v1.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)
		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 = CFrame.new(PositionTable["x"],PositionTable["y"],PositionTable["z"])
		Part.Anchored = true
		Part.CanCollide = false
		Part.Name = "Head"
		local Humanoid = Instance.new("Humanoid")
		Humanoid.Parent = Model
end
AddAMessageToPlayer = function(encodedtable)
	local decodedtable = HttpService:JSONDecode(encodedtable)
	if typeof(decodedtable) == "table" then
		for i,v in pairs(decodedtable) do
			print(i,v)
		end
		pcall(function()
			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	
end
UpdatePosition = function(PositionTablee)
	local UpdateTable = HttpService:JSONDecode(PositionTablee)
	local PlayerName = UpdateTable["PlayerName"]
	pcall(function()
		if game.Workspace:FindFirstChild(PlayerName) then
			game.Workspace[PlayerName].Head.CFrame = CFrame.new(UpdateTable["x"],UpdateTable["y"],UpdateTable["z"])
		end
	end)	
end	
RemovePlayer = function(player)
	if typeof(player) == "string" then
		if game.Workspace:FindFirstChild(player) then
			game.Workspace[player]:Destroy()
		end
	end
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)

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Wait()
	local PositionTable = HttpService:JSONEncode({["PlayerName"] = tostring(player.Name).."Clone",["x"] = player.Character:WaitForChild("HumanoidRootPart").CFrame.x,["y"] = player.Character:WaitForChild("HumanoidRootPart").CFrame.y,["z"] = player.Character:WaitForChild("HumanoidRootPart").CFrame.z})
	MessagingService:PublishAsync("Multiplayer",PositionTable)
	player.Chatted:Connect(function(message)
		local MessageTable = HttpService:JSONEncode({["PlayerName"] = player.Name,["Message"] = message,["PlayerId"] = player.UserId})
		MessagingService:PublishAsync("MultiplayerChat",MessageTable)
	end)	
	spawn(function()
		while player 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"] = tostring(player.Name).."Clone",["x"] = player.Character:WaitForChild("HumanoidRootPart").CFrame.x,["y"] = player.Character:WaitForChild("HumanoidRootPart").CFrame.y,["z"] = player.Character:WaitForChild("HumanoidRootPart").CFrame.z})
					MessagingService:PublishAsync("UpdatePlayer",PositionTable)
				end)	
			end
			wait(0.3)
		end
	end)
end)
game.Players.PlayerRemoving:Connect(function(player)
	MessagingService:PublishAsync("RemoveMultiPlayer",player.Name)
end)


did you found any solutions so far

I’ll figure out a solution tomorrow. (BST)

Ok im gonna wait till you come back

did you found anything? or you couldn’t find anything

I’ll test stuff out now and get back to you soon.

I fixed it! Read this thread I made to explain what was going on. Are you up for testing? Let me know and i’ll send you the updated code here.

im ready for tests Gonna wait for you

Ready soon. Just fixing a few things that are not working right now.

I think I fixed it wanna test it?

and there will be a problem you will see only people that joined after you if you wasn’t the first player to join it

Im working on a thing that would add getallplayers thing but messagingservice limits won’t let me go any further

join this game Multiplayer Test - Roblox

rip this what i see in-game
image
even tho it works fine in roblox studio

By the way this is my fixed code. Multiplayer chat doesn’t seem too stable.
Don’t replace your current script, just create a new script and put this in, and disable the old one, just incase something goes wrong.

print("Script Started v1.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["Data"])
	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 = CFrame.new(PositionTable["x"],PositionTable["y"],PositionTable["z"])
	Part.Anchored = true
	Part.CanCollide = false
	Part.Name = "Head"
	local Humanoid = Instance.new("Humanoid")
	Humanoid.Parent = Model
end
AddAMessageToPlayer = function(encodedtable)
	local decodedtable = HttpService:JSONDecode(encodedtable["Data"])
	if typeof(decodedtable) == "table" then
		for i,v in pairs(decodedtable) do
			print(i,v)
		end
		pcall(function()
			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	
end
UpdatePosition = function(PositionTablee)
	local UpdateTable = HttpService:JSONDecode(PositionTablee["Data"])
	local PlayerName = UpdateTable["PlayerName"]
	pcall(function()
		if game.Workspace:FindFirstChild(PlayerName) then
			game.Workspace[PlayerName].Head.CFrame = CFrame.new(UpdateTable["x"],UpdateTable["y"],UpdateTable["z"])
		end
	end)	
end	
RemovePlayer = function(player)
	if typeof(player) == "string" then
		if game.Workspace:FindFirstChild(player) then
			game.Workspace[player]:Destroy()
		end
	end
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)
		
local joined = function(player)
	player.CharacterAppearanceLoaded:Wait()
	print(player.Name)
	local PositionTable = HttpService:JSONEncode({["PlayerName"] = tostring(player.Name).."-Clone",["x"] = player.Character:WaitForChild("HumanoidRootPart").CFrame.x,["y"] = player.Character:WaitForChild("HumanoidRootPart").CFrame.y,["z"] = player.Character:WaitForChild("HumanoidRootPart").CFrame.z})
	print(PositionTable)
	MessagingService:PublishAsync("Multiplayer",PositionTable)
	player.Chatted:Connect(function(message)
		local MessageTable = HttpService:JSONEncode({["PlayerName"] = player.Name,["Message"] = message,["PlayerId"] = player.UserId})
		MessagingService:PublishAsync("MultiplayerChat",MessageTable)
	end)	
	spawn(function()
		while player 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"] = tostring(player.Name).."-Clone",["x"] = player.Character:WaitForChild("HumanoidRootPart").CFrame.x,["y"] = player.Character:WaitForChild("HumanoidRootPart").CFrame.y,["z"] = player.Character:WaitForChild("HumanoidRootPart").CFrame.z})
					MessagingService:PublishAsync("UpdatePlayer",PositionTable)
				end)	
			end
			wait(0.3)
		end
	end)
end
game.Players.PlayerRemoving:Connect(function(player)
	MessagingService:PublishAsync("RemoveMultiPlayer",player.Name)
end)

for i, v in pairs(game.Players:GetChildren()) do
	joined(v)
end

wait()
game.Players.PlayerAdded:Connect(joined)

Sadly, with all of the positioner updates, you are reaching the limit quite quick.

I maked it work join the game .

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.