Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can you use MessagingService with TeleportService?

I'm trying to use Messaging service to give the Teleport Data to another game, Game 1 teleports you to game 2 but also sends the message. Game 2 is supposed to Receive the message and give the location if the message is given.

I'm doing this method to grab multiple Teleport Data into 1 game.

(Script in part of click detector in first game)

local placeID_1 = 4505065903
local placeID_2 = 4483453486
local TeleportService = game:GetService("TeleportService")
local Ms = game:GetService("MessagingService")
local Message = ("Why")
Ms:SubscribeAsync("TeleportService",function(Message)
	print(Message.Data)
	print(Message.Time)
end)

script.Parent.MouseClick:Connect(function(player)

TeleportService:Teleport(placeID_1, player)
end)

script.Parent.MouseClick:Connect()

This is where you click on the brick and it teleports you, but it also Subscribes the message into TeleportService

(Local Script in StarterGui of second game)


local Data = game:GetService("TeleportService"):GetLocalPlayerTeleportData()
local MS = game:GetService("MessagingService")
MS:PublishAsync("TeleportService", function(Message)
	game:GetService("TeleportService"):GetLocalPlayerTeleportData(Message)
	game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
   	game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(-232.3, 148.4, -236.85)
end)

This is where it publishes it and grabs the data and moves your player to the designated location

It teleports you to the game and stuff, but it doesn't teleport your character to the designated location and then it says this in the developer console output: --Messaging service can only be executed by game server

2 comments

0

use a remote event to execute it on the server. because it wont let it work on client for safety reasons.

0

How do I call it in Remote event?

1 answer

This is redundant usage of MessagingService, to transmit teleport data between servers you should be usig the TeleportService:Teleport() method itself. The third parameter is the data to be passed to the destination space. This data is then recieved by the destination space through the GetLocalPlayerTeleportData() method. This is outlined in the wiki.

Place 1

local placeID_1 = 4505065903
local placeID_2 = 4483453486
local TeleportService = game:GetService("TeleportService")

script.Parent.MouseClick:Connect(function(player)
	TeleportService:Teleport(placeID_1, player, "Data to be passed can be a table, string, number or  bool")
end)

Place 2

local Data = game:GetService("TeleportService"):GetLocalPlayerTeleportData()
print(Data) --> "Data to be passed can be a table, string, number or  bool"

3 comments

0

The thing is, I want to use MULTIPLE datas for one place, if I did that way then it would confuse the script on which data to give. Say there are 3 places 1 2 and 3, 2 and 3 both lead to 1 but in different ways. say 2 is from a cave, and 3 is from a road way. You want 2 to spawn you at the entrance of the cave but you also want players who came from the road way to be spawned over there.

0

then store the data in every place for what spawn and on the server OnPlayerAdded -> OnCharacterAdded (spawn at location)

0

Exactly, your data can be a table and carry a lot of information at once, such as values to work with conditions.

This discussion is preserved as it was. New answers, comments, and votes are closed.