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

How would I fix a script that errors as Unable to cast Instance to int?

local Player= game.Players.LocalPlayer
local Cam = workspace.CurrentCamera
local TeleportService = game:GetService("TeleportService")
local Mouse=Player:GetMouse()
Mouse.Button2Down:connect(function()
	if Cam.CameraSubject== workspace.Yellow then
	TeleportService:Teleport(Player,184968122)
	elseif Cam.CameraSubject==workspace.Green then
		TeleportService:Teleport(Player,182114422)
	end
end)

I doubt this should work on play solo mode so I tried it on a normal server and it just errors as "Unable to cast Instance to int". This is in a localscript inside of StarterGui(I feel kind of bad asking since I feel like its an obvious mistake, and yes, this is my first time trying to use TeleportService)

1 answer

✓ Accepted answer

The :Teleport()method's arguments go in the order of Place ID, THEN the player. You have them switched, so just change line 7 to this:

TeleportService:Teleport(184968122,Player)

and line 9 to this:

TeleportService:Teleport(182114422,Player)

and you're good to go! (Assuming the Place IDs are correct)

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