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

ReserveServer not working? Gives error every time

Asked by 4 years ago

Hi, I got this script, and it wont work because it keep giving an error.

local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")

local code = TS:ReserveServer(3533731366)

local players = game.Players:GetPlayers()

function onTouched(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        TS:TeleportToPrivateServer(3533731366, code, [game.Players:FindFirstChild(hit.Parent.Name)])
    end
end

script.Parent.Touched:Connect(onTouched)

if you look at the line that says:

TS:TeleportToPrivateServer(3533731366, code, [game.Players:FindFirstChild(hit.Parent.Name)])

the output keeps putting out that the first [ is not supposed to be there.

Thanks, guy

2 answers

Log in to vote
0
Answered by
Elixcore 1337 Moderation Voter
4 years ago

Short answer: It is supposed to be an array.

An array is constructed like this

array = {'hello', 'hi'}

So your code is supposed to be:

TS:TeleportToPrivateServer(3533731366, code, {game.Players:FindFirstChild(hit.Parent.Name)})
Ad
Log in to vote
0
Answered by
U_srname 152
4 years ago

There is a better way of getting the player. This should be your code:

local TS = game:GetService("TeleportService")
local Players = game:GetService("Players") 
local code = TS:ReserveServer(game.PlaceId) -- no need for the id
local players = game.Players:GetPlayers() -- useless variable. you should remove it

function onTouched(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        TS:TeleportToPrivateServer(3533731366, code, game.Players:GetPlayerFromCharacter(hit.Parent)) 
    end
end

script.Parent.Touched:Connect(onTouched)
0
this will error... Elixcore 1337 — 4y
0
^ DeceptiveCaster 3761 — 4y

Answer this question