I'm making a friends UI and it works so far except for when I'm trying to detect if the player's friend is in a different server within the same game or not. It keeps erroring saying TeleportService::GetPlayerPlaceInstanceAsync can only be called from the server. even though I'm calling it in a server script inside server script service??

Error: TeleportService::GetPlayerPlaceInstanceAsync can only be called from the server. Line 30 on the server script

Here is the code:

Server

--// Variables

local events = game:GetService('ReplicatedStorage'):WaitForChild('Events')
local remoteEvents = events:WaitForChild('RemoteEvents')
local remoteFunctions = events:WaitForChild('RemoteFunctions')

local updateFriends = remoteEvents:WaitForChild('UpdateFriends')
local tpToFriend = remoteEvents:WaitForChild('TeleportToFriend')
local getFriendInGame = remoteFunctions:WaitForChild('GetFriendInGame')

local teleportService = game:GetService('TeleportService')

--// Functions

game.Players.PlayerAdded:Connect(function(player)
	wait(2)
	updateFriends:FireClient(player)
end)

tpToFriend.OnServerEvent:Connect(function(player, friendId)
	local success, message, placeId, instanceId = teleportService:GetPlayerPlaceInstanceAsync(friendId)
	if success then
		teleportService:TeleportToPlaceInstance(placeId, instanceId, player)
	else
		print('Teleport error: ' .. message)
	end
end)

function getFriendInGame.OnServerInvoke(player, friendId)
	local success, message, placeId, instanceId = teleportService:GetPlayerPlaceInstanceAsync(friendId)
	if success then
		return true
	else
		return false
	end
end

Client

local join = newLabel.Join
local getFriend = getFriendInGame:InvokeServer(friends.Id)
if getFriend then
	join.Visible = true
end
join.MouseButton1Down:Connect(function()
	print('Joining ' .. friends.Username .. "'s server!")
	animateButton(join, join:WaitForChild('Shadow'), {0.9, 0, 0.5, 0}, {0.9, 0, 0.5, 3}, false)
	tpToFriend:FireServer(friends.Id)
end)

3 comments

0

Probably because you might be testing in studio, where everything runs locally

0

just go to the test tab and try running a server