Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
tumadrina 179
9 years ago
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

Log in to vote
2
Answered by
Discern 1007 Moderation Voter
9 years ago

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)

Ad

Answer this question