try to remove this break maybe?
1 Like
So like this?
local lobby = game.Workspace.LobbyTeleport
local playerisIn = false
while wait(1) do
for i, v in pairs(game.Workspace:GetChildren()) do
if v.Name == "BattleZoneAreaPart" then
playerisIn = false
local region = Region3.new(v.Position - (v.Size/2), v.Position + (v.Size/2))
local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())
for _, part in pairs(parts) do
if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
playerisIn = true
else
playerisIn = false
end
end
end
if playerisIn == true then
game.ReplicatedStorage.AddPlayerToTable:FireServer()
else
game.ReplicatedStorage.RemovePlayerFromTable:FireServer()
end
end
end
or like this?
local lobby = game.Workspace.LobbyTeleport
local playerisIn = false
while wait(1) do
for i, v in pairs(game.Workspace:GetChildren()) do
if v.Name == "BattleZoneAreaPart" then
playerisIn = false
local region = Region3.new(v.Position - (v.Size/2), v.Position + (v.Size/2))
local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())
for _, part in pairs(parts) do
playerisIn = false
end
end
end
if playerisIn == true then
game.ReplicatedStorage.AddPlayerToTable:FireServer()
else
game.ReplicatedStorage.RemovePlayerFromTable:FireServer()
end
end
end
i am pretty sure that thats not the issue.
i earlier printed the table componenets
and it did print the playername
@YT_Forceman, @HemanshuGaming, the only problem with the script is that it’s not teleporting the players.
local lobby = game.Workspace.LobbyTeleport
local inRound = game.ReplicatedStorage.InRound
local playersInPartRegion = {}
game.ReplicatedStorage.AddPlayerToTable.OnServerEvent:Connect(function(playerToAdd)
if not table.find(playersInPartRegion,playerToAdd.Name) then
table.insert(playersInPartRegion, playerToAdd.Name)
end
end)
game.ReplicatedStorage.RemovePlayerFromTable.OnServerEvent:Connect(function(playerToRem)
if table.find(playersInPartRegion, playerToRem.Name) then
table.remove(playersInPartRegion, playerToRem.Name)
end
end)
while wait(5) do
if #playersInPartRegion < 3 and #playersInPartRegion > 0 then
for _, player in pairs(game.Players:GetChildren()) do
if table.find(playersInPartRegion, player.Name) then
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
humanoidRootPart.Position = lobby.Position
end
end
end
end
Also in the LocalScript in starterGui,
Change it to
local lobby = game.Workspace.LobbyTeleport
local playerisIn = false
while wait(1) do
for i, v in pairs(game.Workspace:GetChildren()) do
if v.Name == "BattleZoneAreaPart" then
playerisIn = false
local region = Region3.new(v.Position - (v.Size/2), v.Position + (v.Size/2))
local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())
for _, part in pairs(parts) do
if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
playerisIn = true
else
playerisIn = false
end
end
end
if playerisIn == true then
game.ReplicatedStorage.AddPlayerToTable:FireServer()
else
game.ReplicatedStorage.RemovePlayerFromTable:FireServer()
end
end
end
1 Like
I can’t do it right now, I will change it later.
I tested the script, but it prints an error, and also it keeps teleporting players again (It lags a lot too).
This is the picture of the error (The error is in line 16 in the script, located in ServerScriptService):
local lobby = game.Workspace.LobbyTeleport
local inRound = game.ReplicatedStorage.InRound
local playersInPartRegion = {}
game.ReplicatedStorage.AddPlayerToTable.OnServerEvent:Connect(function(playerToAdd)
if not table.find(playersInPartRegion,playerToAdd.Name) then
table.insert(playersInPartRegion, playerToAdd.Name)
end
end)
game.ReplicatedStorage.RemovePlayerFromTable.OnServerEvent:Connect(function(playerToRem)
if table.find(playersInPartRegion, playerToRem.Name) then
local Count = 0
for _,index in pairs(playersInPartRegion) do
Count = Count + 1
if index == PlayerToRem.Name then
table.remove(playersInPartRegion,Count)
break
end
end
end
end)
while wait(5) do
if #playersInPartRegion < 3 and #playersInPartRegion > 0 then
for _, player in pairs(game.Players:GetChildren()) do
if table.find(playersInPartRegion, player.Name) then
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
humanoidRootPart.Position = lobby.Position
end
end
break -- Now it wont Teleport Players Again. We Break the Loop And It stops Checking
end
end
``
2 Likes
Thank you for helping me, I never thought this would get this long. Also do I need to credit you?