Yeah, I’m probably not thinking right, but how do I teleport? I’m having an issue with the placeId. In this code I kinda took from another post, and it said to replace the game.PlaceId to the ID of the game I’m trying to teleport to. Instead I just created a variable.
The error code says HTTP 403 (Forbidden) at local serverCode = teleportService:ReserveServer(PlaceId) in the CountDown function. It does start the countdown, but I’ve tried this in game and out of studio, and the teleport doesn’t work. Here’s the code:
local seats = workspace.Seats
local teleportService = game:GetService("TeleportService")
local num = 0
local playersInSeats = {}
local countdown = false
local PlaceId = 5239966475
local function countDown()
if not countdown then
countdown = true
print("Start countdown")
playersInSeats = {}
for i = 10,1,-1 do --first number changes countdown
if num < 1 then break end -- if everyone gets off, reset timer
if num == #seats:GetChildren() then break end -- if seats are full, teleport
wait(1)
end
if num >= 1 then -- changes minimum number of players
print("Start game")
local serverCode = teleportService:ReserveServer(PlaceId) -- change game.PlaceId to the place id
for _,seat in pairs(seats:GetChildren()) do
if seat.Occupant then
local plr = game.Players:GetPlayerFromCharacter(seat.Occupant.Parent) -- occupant is the humanoid, hence why
table.insert(playersInSeats,plr)
end
end
for _,plr in pairs(playersInSeats) do
print(plr)
end
teleportService:TeleportToPrivateServer(PlaceId,serverCode,game.Players:GetPlayers()) -- change game.PlaceId to the place id, was playersInSeats
countdown = false
else
countdown = false
end
end
end
for _,seat in pairs(seats:GetChildren()) do
if seat:IsA("Seat") then
seat:GetPropertyChangedSignal("Occupant"):connect(function()
if seat.Occupant ~= nil then
num = num + 1
countDown()
else
num = num - 1
end
end)
end
end
I’m not sure how to fix this and actually make the teleport work. Any help is greatly appreciated, thanks in advance!
That error probably means the place you’re trying to teleport to isn’t in the same universe as the game you’re running this script in. You can’t reserve a private server in a place you don’t own. (Also, keep in mind you can’t test teleporting in Studio. I’d recommend testing in-game otherwise it’ll error.)
I am teleporting from Crazy Killer to Crazy Killer - In Game
And I have been testing in both studio to find the errors and publishing and playing the game on roblox.
Okay, I guess the problem is that you’re testing this in Studio then. I didn’t realize that was the error for when you can’t reserve servers in Studio, oh well. Try doing it in-game and use the developer console (F9) to see if the errors are different there.
Do you have a script in workspace.Seats? It seems like when you loop through seats at the bottom, it’s finding a script. Doing script:GetPropertyChangedSignal("Occupant") would probably throw that error.
That’s what I said would cause the error. An actual fix would be checking IsA VehicleSeat or whatever before trying to be the occupancy changed signal, so that it doesn’t try it on the script in there. A script can’t have an Occupant.
Huh, I’ve been experimenting with this because it is teleporting everyone in the server, not just those who are in the seats. When I specify who I’m teleporting I did seats:GetChildren() though it is still teleporting the whole server. Is there a way to say teleport those who on the seats?