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

"Unable to cast string to int64" even though the argument is an int?

Asked by 4 years ago
Edited 4 years ago

I tried tonumber() an already number. Didn't work

Server Script

repeat wait() until game.Workspace

local TeleportService = game:GetService("TeleportService")

local Remote = script.Parent.Event

Remote.OnServerEvent:Connect(function(SentFrom, Setting, ExtraData)
    if string.lower(Setting) == "teleport" then
        local finished, err = pcall(function()
            local Code = TeleportService:ReserveServer(ExtraData)
            TeleportService:TeleportToPrivateServer(4805466213, Code, {SentFrom})
        end)

        if not finished then
            warn(err)
        end
    end
end)

Local Script

function GenCode(Len, Al, Num, Special, Space)

    local Len_Code = Len

    local Alphabet = Al
    local Numbers = Num
    local SpecialCharacters = Special
    local Space = Space

    local alphabet = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz'
    local numbers = '1234567890'
    local specialcharacters = '{}!@#$%^&*()_+-=[]\\/.,*+'
    local space = ' '
    local output = ''

    local function ReturnUsable()
        local returntable = {}
        if Alphabet == true then
            table.insert(returntable,1,alphabet)
        end
        if Numbers == true then
            table.insert(returntable,1,numbers)
        end
        if SpecialCharacters == true then
            table.insert(returntable,1,specialcharacters)
        end
        if Space == true then
            table.insert(returntable,1,space)
        end
        return returntable
    end

    for i = 1, Len_Code do
        local tables = ReturnUsable()
        local CurrentType = tables[math.random(1,#tables)]
        local a = math.random(1,string.len(CurrentType))
        output = output..string.sub(CurrentType,a,a)
    end

    return output
end

function CreateCode()
    return GenCode(6, true, true, false, false)
end

function CreateGame()
    local Code = CreateCode()
    Remote:FireServer("Teleport", Code) 
end

CreateBtn.MouseButton1Click:Connect(CreateGame)
0
can we see the functions `GenCode`? User#23252 26 — 4y
0
You can't use the placeID / gameID to teleport to a ReservedServer, use the reserved server code maumaumaumaumaumua 628 — 4y
0
all it does is generate a random code with letters and numbers and is returned as a string BradNewTypical 232 — 4y
0
Brad, can we see the function GenCode? User#23252 26 — 4y
View all comments (6 more)
0
Ok now BradNewTypical 232 — 4y
0
NVM, can you just tell me what the function is suppose to do and return? User#23252 26 — 4y
0
It generates a random string that has the length of 6 as the private server code. BradNewTypical 232 — 4y
0
You cannot reserve a server to an invalid PlaceId Ziffixture 6913 — 4y
0
ohh i see the problem User#23252 26 — 4y
0
lemme write an answer User#23252 26 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

The function TeleportService:ReserveServer takes 1 argument. That argument is the place id of the place you want to reserve a server at.. the function returns a code, this code is passed to TeleportService:TeleportToPrivateServer as the second argument.. The argument list of TeleportService:TeleportToPrivateServer is:

1: onces again the place Id where you reserved server

2:server code returned from ReserveServer

3: players to teleport

however, you passed a custom made(ExtraData) id to ReserveServer, which i assume is a string..

learn more here

0
so no fancy code for joining? BradNewTypical 232 — 4y
0
not at all User#23252 26 — 4y
0
How would I make one then? Where you enter in a special code and join the special server. BradNewTypical 232 — 4y
0
If you truly wish to do this, you can take the output form ReserveServer, and scramble it or hash it in your own way. Ensure you create a function that can decode it. Ziffixture 6913 — 4y
0
Ok, thanks BradNewTypical 232 — 4y
Ad

Answer this question