I want a teleport like in the game camping. Here is my code:
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local Seats = script.Parent.Seats.Seat
local PlaceId = 5139316099
local minPlayerCount = 1
local PlayerTable = {}
script.Parent.Touched:Connect(function(hit)
print("1")
if hit.Parent:FindFirstChild("Humanoid") then
print("2")
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
print("3")
table.insert(PlayerTable, player)
if #PlayerTable >= minPlayerCount then
TeleportService:TeleportPartyAsync(PlaceId, PlayerTable)
print("Enough Players, teleporting")
end
end
end
end)
and it doesn’t seem to work
what’s the error you’re getting?
It doesn’t teleport or print anything
Does it not print the “1”, “2” and “3”? That would mean it’s not detecting when part “hit” is touching part “script.parent”.
it doesn’t print anything. The touch function is what’s wrong I think
Here is what happens: https://streamable.com/s6n268
Recoded:
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local Seats = script.Parent.Seats.Seat
local PlaceId = 5139316099
local minPlayerCount = 2
local plrz = {}
local ui = game.ReplicatedStorage.ScreenGui
script.Parent.Touched:Connect(function(hit)
print("Something touched me!")
if hit.Parent:FindFirstChild("Humanoid") then --its a player/npc!
print("Its a player or a npc!")
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then --Its a player for sure
table.insert(plrz, player)
print("Player is in table!")
if #plrz >= minPlayerCount then
TeleportService:SetTeleportGui(ui)
TeleportService:TeleportPartyAsync(PlaceId, plrz)
print("Sending players")
end
end
end
end)