I need help making Portal

Hello guys! im currently working on my first game but im really noob at scripting, but really wanted to learn.

  1. What do you want to achieve? i want it so that when i enter the portal i cant go back unless i defeated all the enemies

  2. What is the issue? i dont know where to start, what to script, you should get what im trying to say.

  3. What solutions have you tried so far? i tried looking for it here and yt but i couldn’t find answer

here is my portal script

local TeleportService  = game:GetService("TeleportService")
local gameID = 

local function onPartTouch(otherPart)
	local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
	if player then
		TeleportService:Teleport(gameID, player)
	end
end

script.Parent.Touched:Connect(onPartTouch)

Are your enemies in a NPC folder? If they are then you could check the contents of the folder with a for loop.

yes they are but the problem is i cant make it so that i can only leave the place until i defeated the enemies, more like when i enter the portal( i get telepoted to other place) i cant go back to main game unless all the enemies are gone

If the enemies are destroyed upon death you can simply check if there are enemies via using:

local folder = folderLocation
if #folder:GetChildren() < 1 then
-- Teleport the player.

im not sure if i understand but thnx for help ill try using it

Where is the folder with the enemies located?
I can’t help you if I know nothing about the enemies that need to be defeated, sure there are enemies but your code must know that there are.

i used the zombies in the toolbox for now but i placed it in a folder under workspace

Yes but where is the folder in workspace located? What is the folder called, as I said earlier I cannot help you unless you give me this information.

the folder is called Folder and its directly under workspace

Try this.

local TeleportService  = game:GetService("TeleportService")
local gameID = 

local function onPartTouch(otherPart)
	local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
	if player then
        if #game.Workspace.Folder:GetChildren() == 0 then
		   TeleportService:Teleport(gameID, player)
        end
	end
end

script.Parent.Touched:Connect(onPartTouch)
1 Like

do i replace the portal script to this? or place it somewhere?

Yes replace the portal script with this.

1 Like