This script is meant to teleport players in a part once there are 2 players or more in it. The problem is, I keep getting this error. Please tell me the errors if you could find it, and also I had to do so much editing so the script is a hot mess right now.
Picture: https://prnt.sc/r4bz4y
Errors: Line 38: Script timeout: exhausted allowed execution time Line 11: function getPlayersInPart
local Car = workspace.Car2
local matchPart = workspace:WaitForChild("matchPart") --Part to use to check
local function posInPos(pos,low,high)
--A really long condition making sure that pos is between low and high
return pos.X >= low.X and pos.X<=high.X and pos.Y >= low.Y and pos.Y<=high.Y and pos.Z >= low.Z and pos.Z<=high.Z
end
local function getPlayersInPart(part)
local results = {}
for _,plr in pairs(game:GetService("Players"):GetPlayers()) do
--For every player, get their character
local char = plr.Character
if char then
local humRoot = char:FindFirstChild("HumanoidRootPart")
if humRoot then --Check to see if that character's humanoidRootPart is inside of the part
local pos = humRoot.Position
local low = part.Position - (part.Size/2)
local high = part.Position + (part.Size/2)
if posInPos(pos, low, high) then
--If so, add it to the results
table.insert(results, plr)
end
end
end
end
--Return the results
return results
end
--Now, to teleport when we have enough players
local teleportAt = 2 --Players to teleport at
local placeIdToReserve = 4699682805 --Place to reserve
local teleS = game:GetService("TeleportService")
while true do
local results = getPlayersInPart(matchPart)
--If enough players, teleport them to a new reserved server
if #results >= teleportAt then
game.Players:GetChildren(results).PlayerGui.Reset:remove() --removes the exit ui from the playergui
game.Workspace.TeleportPad.Script.Disabled = true --disables script so they can't use teleport pad that teleports them in the part
game.Workspace.TeleportPad.Transparency = 1 --makes it invisible
wait(2) -- Time it takes before the Car leaves
for i = 1,100 do
Car:TranslateBy(Vector3.new(0,0,-1)) -- Goes straight
wait()
end
local code = teleS:ReserveServer(placeIdToReserve)
teleS:TeleportToPrivateServer(placeIdToReserve,code,results) --teleports them
wait(2)
for i = 1,100 do
Car:TranslateBy(Vector3.new(0,0,1)) -- Goes back
wait()
end
wait(1)
game.Workspace.TeleportPad.Script.Disabled = false
game.Workspace.TeleportPad.Transparency = 0
wait(1)
end
end
