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

My game join script isnt working any help? (unable to cast value)

Asked by 6 years ago
Edited 6 years ago
while true do
    wait(1)
    print ("Detect")
    local Players = game.ServerScriptService.Waiting:GetChildren()
    if #Players >= 1 then
        game.ServerScriptService.Info.Value = "Intermission..."
        --wait (10)
        local Players = game.ServerScriptService.Waiting:GetChildren()
        if #Players >= 1 then
        for i = 1, #Players do
            if game.Players:FindFirstChild(Players[i].Name) ~= nil then
                if game.Players[Players[i].Name].Waiting.Value == true then
                    local a = Instance.new ("ObjectValue")
                    a.Name = Players[i].Name
                    a.Value = Players[i]
                    a.Parent = game.ServerScriptService.Vertified
                end
            end
        end
            local a = game.ServerScriptService.Waiting:GetChildren()
            for i = 1, #a do
            a[i]:Destroy()
            end

            local TS = game:GetService("TeleportService")
            local code = TS:ReserveServer(1943783356)

            wait()
            local b = game.ServerScriptService.Vertified:GetChildren()
                for o = 1, #a do
                    player = b[o].Value
                    print (player:GetFullName())--Outputs "shanethegamer142"(my user name)
                    TS:TeleportToPrivateServer(1943783356,code,player)--errors "unable to Cast value to objects"
        end
        end
    else
    game.ServerScriptService.Info.Value = "Need More Players"
    end
end

1 answer

Log in to vote
2
Answered by 6 years ago

TeleportToPrivateServer requires an array of players not the indavidual player which is why you are getting that error.

Assuming that b[o].Value is a player instance then you should built a array instead. Exalple:-

...

local TS = game:GetService("TeleportService")
local itms = game.ServerScriptService.Vertified:GetChildren()
local plrList = {}
for i = 1, #itms  do
    plrList[#plrList+1] = itms[i].Value
end

-- tepeort using the array
 TS:TeleportToPrivateServer(1943783356,TS:ReserveServer(1943783356) , plrList )

I hope this helps.

0
will it work even if there is only 1 player? ForgotenR4 68 — 6y
1
Yes as long as you pass an array of player instances. User#5423 17 — 6y
0
im getting a error TeleportService;TeleportToPrivateServer must be passed an array of players ForgotenR4 68 — 6y
1
make sure that your object values in Vertified holds the player instance User#5423 17 — 6y
0
yep it works now dude thx so much ForgotenR4 68 — 6y
Ad

Answer this question