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

Unable to cast value to object in my teleport script?

Hi again i ran into another error in my teleporting script. This time it is unable to cast value to object. the error is at line 18. Heres the script.

while true do
local Teleporters = {}
local IsInTable = false
local TS = game:GetService("TeleportService")

local code = TS:ReserveServer(5970897194)

script.Parent.Touched:Connect(function(t)
	if t.Parent:FindFirstChild("Humanoid") then
		if IsInTable == true then return end
		table.insert(Teleporters,game.Players:FindFirstChild(t.Parent.Name))
		IsInTable = true
		for i = 10,0,-1 do
			script.Parent.BillboardGui.TextLabel.Text = i
			wait(1)
		end
			for i, v in pairs(Teleporters) do
			TS:TeleportToPrivateServer(5970897194,code,v)
			table.remove(Teleporters,v)
		end
		end
	end)
	wait()
end
wait()


1 answer

✓ Accepted answer

The third argument to TeleportToPrivateServer is an array of players. You are passing v which only refers to a single player.

What you have to do is move the teleport call before the for loop and do the following: TS:TeleportToPrivateServer(5970897194, code, Teleporters) This way you pass the whole array of players who need to be teleported at once.

2 comments

0

Thanks! but my game is crashed when i get teleported

0

crashed*

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