Teleport Data Help

So Im trying to teleport the user to a place, but I get the error, Cannot cast value to object. This error came on the line of teleport. Whats wrong?

local TeleportService = game:GetService("TeleportService")
local setting = require(game.ServerScriptService.SETTINGS)

game.ReplicatedStorage.Teleport.OnServerEvent:Connect(function(rank, plr)
	print("fired")
	local teleportData = {
    RankId = rank,
    GroupId = setting.Settings.GroupId,
	Key = setting.Settings.Key
	}
	print("after")
	TeleportService:Teleport(4790905474, plr.UserId, teleportData)
	print("teleported")
end)

You have to use just the player, not its UserId

local TeleportService = game:GetService(“TeleportService”)

game.Players.PlayerAdded:Connect(function(plr)
wait()
TeleportService:Teleport(placeID, plr, config)
end)

The player is always passed as the first argument of OnServerEvent, therefore it is always the first parameter. Secondly, you have to use the actual player to teleport them, not their UserId.

Testing now, hold on a moment.

Make sure to change what @Raretendoblox said as well.

I did this:

event:FireServer(rank, plr)

and then in the teleport script:

local TeleportService = game:GetService("TeleportService")
local setting = require(game.ServerScriptService.SETTINGS)

game.ReplicatedStorage.Teleport.OnServerEvent:Connect(function(rank, plr)
	print("fired")
	local teleportData = {
    RankId = rank,
    GroupId = setting.Settings.GroupId,
	Key = setting.Settings.Key
	}
	print("after")
	TeleportService:Teleport(4790905474, plr, teleportData)
	print("teleported")
end)

But I get this in the output:

No, no, don’t provide player argument in the :FireServer(), just use rank. However, on the server, do this

local TeleportService = game:GetService("TeleportService")
local setting = require(game.ServerScriptService.SETTINGS)

game.ReplicatedStorage.Teleport.OnServerEvent:Connect(function(plr, rank) --switched plr and rank
	print("fired")
	local teleportData = {
    RankId = rank,
    GroupId = setting.Settings.GroupId,
	Key = setting.Settings.Key
	}
	print("after")
	TeleportService:Teleport(4790905474, plr, teleportData) --removed .UserId
	print("teleported")
end)
1 Like

No, Im saying in the script where the event is fired is in a local script, so I referenced player as local plr = game.Players.LocalPlayer and then I did
local rank = game.ServerScriptService.Folder.Rank.Value
game.ReplicatedStorage.Event:FireServer(rank, plr)

Yeah, you don’t have to give it player argument. just do :FireServer(rank)

So how do I find the player, in the onserverevent?

No matter what the arguments are, Player will always be passed through FireEvent, so you dont need to state it as an argument.

But on the ServerSide, you HAVE TO to state the [Player] as the first argument, and so on.

so instead should I do ?
:FireServer(plr, rank)

You can if you want, it will work either way, with or without plr as one of the arguments.

(Make sure that FireServer is being fired on the ClientSide; which should be in a LocalScript )

Should the on server event also be in a local script?

Definitely NOT. It needs to be a Script.