Teleport script not working?

my script teleports a player to a different game when the players lives reaches 0 but it doesnt work and i get this error

“Argument 2 missing or nil”

heres my script

local LivesFld = game.ReplicatedStorage.LiveEvents
local ts = game:GetService("TeleportService")
local placeid = "10197848753"
	--put your place's id there ^
	local Debounce = {}

LivesFld.DiedFired.OnServerEvent:Connect(function(Player)
	if Debounce[Player] then return end
	Debounce[Player] = true

	local Lives = Player:WaitForChild("SystemFolder"):WaitForChild("Lives")
	Lives.Value -= 1

	Player.CharacterAdded:Connect(function()
		if Lives.Value <= 1 then
			Lives.Value = 1
			spawn(function()
				ts:TeleportAsync(placeid, Debounce[Player])
			end)
		end
	end)

	wait(.25)
	Debounce[Player] = nil
end)
1 Like

Change that line to:
ts:TeleportAsync(placeid, Player)

3 Likes

It doesn’t make sense that the fact that Debounce[player] is a boolean.

2 Likes

it says Unable to cast value to Objects, is that because im in roblox studio?

i got rid of that and changed it to a normal debounce within the script, no boolean

Ok, this is because TeleportAsync() has the second argument as objects meaning an array, if you would like to do it that way then you would have to TeleportService:TeleportAsync(YOUR_PLACE_ID_HERE, {Player}) -- where player is the parameter from the RemoteEvent.

See more:
https://developer.roblox.com/en-us/api-reference/function/TeleportService/TeleportAsync

2 Likes

thank you for the help but how do you think i can implement this into my script? i just dont know how i would go about doing this.

1 Like

It’s really simple just put brackets and put the player in it, like so:

local LivesFld = game.ReplicatedStorage.LiveEvents
local ts = game:GetService("TeleportService")
local placeid = "10197848753"
	--put your place's id there ^
	local Debounce = {}

LivesFld.DiedFired.OnServerEvent:Connect(function(Player)
	if Debounce[Player] then return end
	Debounce[Player] = true

	local Lives = Player:WaitForChild("SystemFolder"):WaitForChild("Lives")
	Lives.Value -= 1

	Player.CharacterAdded:Connect(function()
		if Lives.Value <= 1 then
			Lives.Value = 1
			spawn(function()
				ts:TeleportAsync(placeid, {Player})
			end)
		end
	end)

	wait(.25)
	Debounce[Player] = nil
end)
1 Like

still says Unable to cast value to Objects

so when i play in game (outside of studio) it says place is restricted but i dont want to make it public so people can just join it, any fix?

Can you post me the client script of where it fires the remote?. If you want to test it outside the game, you’ll have to make it public or at least only developers can teleport to it.