Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

10 comments

0

can we see the functions GenCode?

0

You can't use the placeID / gameID to teleport to a ReservedServer, use the reserved server code

0

all it does is generate a random code with letters and numbers and is returned as a string

0

Brad, can we see the function GenCode?

0

Ok now

0

NVM, can you just tell me what the function is suppose to do and return?

0

It generates a random string that has the length of 6 as the private server code.

0

You cannot reserve a server to an invalid PlaceId

0

ohh i see the problem

0

lemme write an answer

1 answer

✓ Accepted answer

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

5 comments

0

so no fancy code for joining?

0

not at all

0

How would I make one then? Where you enter in a special code and join the special server.

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.

0

Ok, thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.