Player doesn't teleport

I tested your script, but it’s not teleporting. There are no errors in the output for your script.

Are you sure that the Gets Added To the table when the player enters the Region?
Did you Script The Region3 Yet?

1 Like

I just put the part in the table. I didn’t script the Region3 yet.

I Suggest You watching the Tutorial I Linked to you Earlier.
From that, You can See if Player is Near the Part.

If the Player is, Just fire a Remote Event which you created Earlier
Which adds the Player into the Table.

1 Like

Change that to:

if #PlayersInPartRegion >= 1 then

just like what @superMathMan9 said.

@superMathMan9, and @Abcreator already said that, and I want to make if there are 1 player or less than 2 player.

Oh, Then Change it To

if #PlayersInPartRegion < 2 and #PlayersInPartRegion > 0 then -- Two Players Are There or 1 Player is There(It wont Run if More then Two)

end
1 Like

Oh, I never thought about > 0.

I watched the tutorial, and this is the script, but I don’t know what to put inside the in pairs loop. AlvinBlox put the SoundRegion, but I’m not using a sound.

This is the script:

while wait(1) do
	for i, v in pairs() do
		playerisIn = false
		local region = Region3.new(v.Position - (v.Size/2), v.Position + (v.Size/2))
	end
end
while wait(1) do
	for i, v in pairs(game.Workspace:GetChildren()) do
		if v.Name == "ThePartYouAddedsName" then -- Change it to Your Parts Name Which U added in workspace (It covers the orignal part)
            playerisIn = false
	       	local region = Region3.new(v.Position - (v.Size/2), v.Position + (v.Size/2)) 
        end
	end
end
1 Like

So since the part is in workspace, you put game.Workspace:GetChildren(), and you check the part name by if v.Name, right?

Yes Exactly.
We Get all Children of Workspace And We check if the Instance we got Has the Name as
the Part which we want.

1 Like

I put together all of the script, but it’s still not teleporting.

local lobby = game.Workspace.LobbyTeleport
local inRound = game.ReplicatedStorage.InRound
local playersInPartRegion = {game.Workspace.BattleZoneAreaPart}
local playerisIn = false



game.ReplicatedStorage.AddPlayerToTable.OnServerEvent:Connect(function(PlayerToAdd)
	table.insert(playersInPartRegion,PlayerToAdd.Name)
end)

game.ReplicatedStorage.RemovePlayerFromTable.OnServerEvent:Connect(function(PlayerToRem)
	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)

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))
		end		
	end
end


while wait(1) do
	if #playersInPartRegion <2 then
		for _, player in pairs(game.Players:GetChildren()) do
			for i,index in pairs(playersInPartRegion) do
				if index == player.Name then
					local char = player.Character
					char:MoveTo(lobby.Position)
				end
			end			
		end
	end
end

You Need to Put that

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))
		end		
	end
end

In A LocalScript in StarterGui.
Dont Combine it with your Normal Script.

And You Dint write the Full Script, watch the Full Tutorial.
And Get the FullScript.

Once you finish the Tutorial,
Show the Final Script.

1 Like

I’ve watched the tutorial, but I think the LocalScript inside StarterGui teleports every player that is touching the part.
ServerScriptService:

local lobby = game.Workspace.LobbyTeleport
local inRound = game.ReplicatedStorage.InRound
local playersInPartRegion = {game.Workspace.BattleZoneAreaPart}
local playerisIn = false



game.ReplicatedStorage.AddPlayerToTable.OnServerEvent:Connect(function(PlayerToAdd)
	table.insert(playersInPartRegion,PlayerToAdd.Name)
end)

game.ReplicatedStorage.RemovePlayerFromTable.OnServerEvent:Connect(function(PlayerToRem)
	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)




while wait(1) do
	if #playersInPartRegion <2 then
		for _, player in pairs(game.Players:GetChildren()) do
			for i,index in pairs(playersInPartRegion) do
				if index == player.Name then
					local char = player.Character
					char:MoveTo(lobby.Position)
				end
			end			
		end
	end
end

LocalScript(Inside StarterGui):

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
					break
				else
					playerisIn = false
					  
				end
			end
		end	
		
		if playerisIn == true then
			for _, player in pairs(game.Players:GetChildren()) do
				local char = player.Character
				char:MoveTo(lobby.Position)
				break
			end
		end
	end
end

You dont need to Do that,
You just need to Fire an Event.

As of Here.

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
					break
				else
					playerisIn = false
					  
				end
			end
		end	
		
		if playerisIn == true then
			game.ReplicatedStorage.AddPlayerToTable:FireServer()
          else
            game.ReplicatedStorage.RemovePlayerFromTable:FireServer()
		end
	end
end
1 Like

Then will the part teleport players if there is only 1 player?

Yea it will teleport if there is 1 or 2 players not more than that

1 Like

It doesn’t teleport the player.

This actually means there is only one player.

1 Like