I’m making a teleporter
Folder.ChildAdded:Connect(UpdateGui)
Folder.ChildRemoved:Connect(UpdateGui)
is not working
I have tried moving around the UpdateGui function but nothing happened
-- SERVICES --
local Players = game:GetService('Players')
local ts = game:GetService('TeleportService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
-- REMOTES --
local remote1 = ReplicatedStorage:WaitForChild('Remotes'):WaitForChild('JoinLobby')
local remote2 = ReplicatedStorage:WaitForChild('Remotes'):WaitForChild('LeaveLobby')
-- GAME INFO --
local PlaceId = 9479160887
local maxPlayers = 16
local teleport = script.Parent
-- PLAYERS AND NODES --
local Folder = script.Parent:WaitForChild('Players')
local node = script.Parent:WaitForChild('TeleportNode')
local node2 = script.Parent:WaitForChild('TeleportNode2')
-- UI STUFF --
local playerCount = script.Parent:WaitForChild('billboard'):WaitForChild('SurfaceGui'):WaitForChild('TextLabel')
local timerText = script.Parent:WaitForChild('billboard'):WaitForChild('timer'):WaitForChild('TextLabel')
local intermissionLength = 30
local TimerActive = false
local debounce = false
local DetectEnd = {}
local studs = 10
-- FUNCTIONS --
function UpdateGui()
playerCount.Text = tostring(#Folder:GetChildren())..'/'..tostring(maxPlayers)
end
function checkIfExists(Character) -- checks if player exists
for _,value in pairs(Folder:GetChildren()) do
if value.Value == Character then return true end
end
return false
end
function teleportParty()
local Plrs = {}
for _,value in pairs(Folder:GetChildren()) do
if not value then continue end
table.insert(Plrs,Players:GetPlayerFromCharacter(value.Value))
end
local Code = ts:ReserveServer(PlaceId)
ts:TeleportToPrivateServer(PlaceId,Code,Plrs)
Folder:ClearAllChildren()
end
function timer()
if TimerActive then return end
TimerActive = true
intermissionLength = 30
while task.wait() do
for i = intermissionLength,0,-1 do
timerText.Visible = true
wait(1)
intermissionLength = i
timerText.Text = i
if #Folder:GetChildren() == 0 then
intermissionLength = 30
TimerActive = false
return
end
end
if #Folder:GetChildren() >= maxPlayers or intermissionLength == 0 then
TimerActive = false
teleportParty()
end
end
end
script.Parent.Touched:Connect(function(part)
if not part.Parent:FindFirstChild('Humanoid') then return end
if debounce then return end
debounce = true
local player = part.Parent
if not checkIfExists(player) then
local Tag = Instance.new('ObjectValue')
Tag.Value = player
Tag.Parent = Folder
table.insert(DetectEnd, player.HumanoidRootPart)
end
if #Folder:GetChildren() > 0 then
timer()
end
debounce = false
end)
while wait() do
table.foreach(DetectEnd, function(index, HumanoidRootPart)
local checkDistance = (HumanoidRootPart.Position - teleport.Position).Magnitude
if checkDistance > studs then
local Player = game.Players:GetPlayerFromCharacter(HumanoidRootPart.Parent)
for _,value in pairs(Folder:GetChildren()) do
if value.Value == Player.Character then
value:Destroy()
end
end
end
end)
end
Folder.ChildAdded:Connect(UpdateGui)
Folder.ChildRemoved:Connect(UpdateGui)
the player count stays at 0