Ad
Log in to vote
0

Players are not being teleported. Unable to cast value to object. How do I fix this?

Asked by 16 days ago
Edited 15 days ago

Client Side Code :

local GameId = 6305504610 --Line 148
print("GameId "..GameId) --Line 149
print("PlayerName "..plr.Name) --Line 150
local teleporting = game.ReplicatedStorage.Check:InvokeServer(plr , GameId) --Line 151

Server Side Code :

local rs = game:GetService("ReplicatedStorage")
local Teleport = game:GetService("TeleportService")
local CNT = 0
local function checkandteleport (plr , GameId)
    GameId = 6305504610
    print("GameId "..tostring(GameId))
    print("Player Name "..plr.Name)
    local plrs = {plr}
    print(tostring(plrs))
    if game.PrivateServerId ~= "" and game.PrivateServerOwnerId ~= 0 then
        print("Teleporting to a Private server")
        local code = Teleport:ReserveServer(GameId)
        print(tostring(GameId))
        print(tostring(plr))
        print(code)
        print("Player getting teleported is "..tostring(plrs))
        local Success,Error = pcall (Teleport:TeleportToPrivateServer(GameId , code , plrs))
        repeat
            print("Error" .. Error)
            CNT = CNT + 1
            wait(5)
            local Success,Error = pcall(Teleport:TeleportToPrivateServer(GameId , code , plrs))
        until Success or CNT == 3

        if CNT == 3 then
            plr:Kick("Failed To Teleport")
        end
    else
        print("Teleporting to a Standard Server")
        print(tostring(GameId))
        print(plr.Name)
        print("Player getting teleported is "..tostring(plrs))
        local Success,Error  = pcall(Teleport:Teleport(GameId , plrs))
        repeat
            print("Error" .. Error)
            CNT = CNT + 1
            wait(5)
            local Success,Error = pcall(Teleport:Teleport(GameId , plrs))
        until Success or CNT == 3

        if CNT == 3 then
            plr:Kick("Failed To Teleport")
        end
    end
end
local check = rs:WaitForChild("Check")
check.OnServerInvoke = checkandteleport

Client Side Output:

Game Id 6305504610
PlayerName nkminion
Unable to cast value to Object
Stack Begin
Script 'Players.nkminion.PlayerGui.Menu.MenuMain' , Line 151
Stack End

Server Side Output:

Game Id 6305504610
Player Name nkminion
table : 0x9b3f29256257dcba
Teleporting to a Standard Server 
6305504610
nkminion
Player getting teleported is table : 0x9b3f29256257dcba
Unable to cast value to Object
Stack Begin
Script 'ServerScriptService.Script' , Line 33 - function checkandteleport
Stack End

Edit : To provide more context , im making a script that checks if you are in a public server or in a private server. If you are in a public server , it teleports you to another public server. If you are in a private server , it teleports you to a standard server. The problem is that the standard server script does not work Please Help!

1 answer

Log in to vote
0
Answered by 11 days ago

I do not know the logic behind this , but I just changed the plrs to plr in Line 33 and Line 38 and it worked :/

Ad

Answer this question