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

trying to teleport a player: "Unable to cast Instance to int64" ??

Asked by 5 years ago

This is a LocalScript inside of a PlayerGui.

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local gui = script.Parent
local placeId = 2528001957

local function onTouched(hit)
    local dude = hit.Parent
    local player = Players:GetPlayerFromCharacter(hit.Parent)

    wait(.5)
    gui.TextButton.Visible = true
    gui.Enabled = true
    workspace.bigwelltp.CanCollide = false
    wait(1)
    workspace.bigwelltp.CanCollide = true

    wait(4)
    gui.TextButton.Visible = false
    gui.TextButton2.Visible = true
    wait(4)
    gui.TextButton2.Visible = false
    gui.TextButton3.Visible = true
    wait(4)
    gui.TextButton3.Visible = false

    gui.TextButton4.Visible = true
    gui.Repent.Visible = true
    gui.YOLO.Visible = true

    gui.Repent.Activated:Connect(function()
        gui.TextButton4.Visible = false
        gui.Repent.Visible = false
        gui.YOLO.Visible = false
        gui.TextButton.Text = "You are forgiven."
        gui.TextButton.Visible = true
        wait(1)
        TeleportService:Teleport(player, placeId)
    end)

    gui.YOLO.Activated:Connect(function()
        gui.TextButton4.Visible = false
        gui.Repent.Visible = false
        gui.YOLO.Visible = false
        gui.TextButton.Visible = true
        dude.Humanoid.Health = 0
    end)

end

workspace.bigwelltp.Touched:Connect(onTouched)

Everything works except for line 37, when the player teleports to a new game. I've used this method to teleport players in other games and it worked just fine. And the game it's supposed to teleport to is a StarterPlace of another game, so it's not like the teleport destination is illegal or anything.

I've tried changing how the player is found (local player = script.Parent.Parent.Parent was what I had originally), but no matter what I do, the same error comes up.

Is there any way to make this work? Or is it a weird bug?

1 answer

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago

You have to switch the values around in the function, because you're making the placeId parameter the the player, and the player parameter the placeId

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local gui = script.Parent
local placeId = 2528001957

local function onTouched(hit)
    local dude = hit.Parent
    local player = Players:GetPlayerFromCharacter(hit.Parent)

    wait(.5)
    gui.TextButton.Visible = true
    gui.Enabled = true
    workspace.bigwelltp.CanCollide = false
    wait(1)
    workspace.bigwelltp.CanCollide = true

    wait(4)
    gui.TextButton.Visible = false
    gui.TextButton2.Visible = true
    wait(4)
    gui.TextButton2.Visible = false
    gui.TextButton3.Visible = true
    wait(4)
    gui.TextButton3.Visible = false

    gui.TextButton4.Visible = true
    gui.Repent.Visible = true
    gui.YOLO.Visible = true

    gui.Repent.Activated:Connect(function()
        gui.TextButton4.Visible = false
        gui.Repent.Visible = false
        gui.YOLO.Visible = false
        gui.TextButton.Text = "You are forgiven."
        gui.TextButton.Visible = true
        wait(1)
        TeleportService:Teleport(placeId, player)
    end)

    gui.YOLO.Activated:Connect(function()
        gui.TextButton4.Visible = false
        gui.Repent.Visible = false
        gui.YOLO.Visible = false
        gui.TextButton.Visible = true
        dude.Humanoid.Health = 0
    end)

end

workspace.bigwelltp.Touched:Connect(onTouched)
0
Oh, wow, that was a really silly mistake. Thanks for pointing that out! PurringThunder 2 — 5y
Ad

Answer this question