UNSOLVABLE! script not working

hello. this script doesnt react if i trigger the prompt to fire the “EXIT” function. it also doesnt work with any other function. what is making the script get stuck? the teleporting works however but is buggy.

PLEASE HELP ):

--SETUP
script.Player_Limit.Value = script.MAIN_MODEL.Value:GetAttribute("PLR_LIMIT")
script.PLACE_ID.Value = script.MAIN_MODEL.Value:GetAttribute("PLACE")



local TS = game:GetService("TeleportService")
local TweenService = game:GetService("TweenService")
local placeId = script.PLACE_ID.Value
local teleporting = false
local spawnTeleport = script.ENTER_Pos.Value
local Leave_TP = script.LEAVE_PART.Value

script.Gui.Value.Frame.players.Text = "Players: " ..#script.People:GetChildren().. "/"..script.Player_Limit.Value..""
script.Gui.Value.Frame.CountDown.Text = script.CountDownTime.Value



local function updateGui()
	script.Gui.Value.Frame.players.Text = "Players: " ..#script.People:GetChildren().. "/"..script.Player_Limit.Value..""
end

local function removeFromList(Character)
	if script.People:FindFirstChild(game.Players:GetPlayerFromCharacter(Character).Name) then
		script.People:FindFirstChild(game.Players:GetPlayerFromCharacter(Character).Name):Destroy()
		updateGui()
	end
end

function Teleport_Players()

	script.EVENTS.FADE_IN:FireAllClients()

	wait(0.2)

	local PlayerTable = {}

	for a, b in ipairs(script.People:GetChildren()) do
		table.insert(PlayerTable, b.Value)
	end
	--local ServerCode = game["Teleport Service"]:ReserveServer(placeId)
	--game["Teleport Service"]:TeleportToPrivateServer(placeId,ServerCode,PlayerTable)
	game.TweenService:Create(script.CAM_PARTS.MOVING.Value,TweenInfo.new(4,Enum.EasingStyle.Sine),{CFrame = script.CAM_PARTS.POS_TWO.Value.CFrame}):Play()
	wait(4)
	script.CAM_PARTS.MOVING.Value.CFrame = script.CAM_PARTS.POS_ONE.Value.CFrame
	script.EVENTS.DOORS:Fire("OPEN")
	for a, b in ipairs(script.People:GetChildren()) do
		b:Destroy()
	end
	table.clear(PlayerTable) --reset the table!
	script.Gui.Value.Frame.Status.Text = "READY"
	updateGui()
	script.EVENTS.DOORS:Fire("OPEN")
end

local Enter_db = true
script.ENTER_PART.Value.Touched:Connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") then


		local char = hit.Parent
		local alreadyExists = false
		if game.Players:GetPlayerFromCharacter(hit.Parent) ~= nil then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if not script.People:FindFirstChild(""..player.Name.."") then
			if #script.People:GetChildren() < script.Player_Limit.Value then
				local Val = Instance.new("ObjectValue",script.People)
				Val.Name = player.Name
				Val.Value = player

				local GUI = script.SCENE_GUI.Value:Clone()
				GUI.Parent = player.PlayerGui

				char:PivotTo(script.ENTER_Pos.Value.CFrame)
				updateGui()
				if #script.People:GetChildren() == script.Player_Limit.Value then
					script.EVENTS.DOORS:Fire("CLOSE")
					wait(0.2)
					Teleport_Players()
				end

				player.CharacterRemoving:connect(function(character)
					removeFromList(character)
					end)
					end
			end
		end
	end
	wait(0.2)
end)

--CountDown
local CountDownTime = script.CountDownTime.Value
local Counting = false
local CountDownLabel = script.Parent.Parent.WALLS.iNVISIBLE_WALL.GUI.Frame.CountDown

local CountDown = CountDownTime

--Sets Counting to false or true depending if there are playsers
script.People.ChildAdded:Connect(function()
	Counting = true
end)
script.People.ChildRemoved:Connect(function()
	if #script.People:GetChildren() ~= 0  then return end--set counting to false if no player
	Counting = false

	--Reset countdown
	CountDown = CountDownTime
	CountDownLabel.Text = CountDown
end)
--Sets Counting to false or true depending if there are playsers
	while true do
		wait(1)
		if not Counting or #script.People:GetChildren() == 0 then CountDown = CountDownTime end
		script.TICK_SOUND.Value:Play()

		CountDown = CountDown -1
		CountDownLabel.Text = CountDown
		updateGui()
		if CountDown == 0 then
			CountDown = CountDownTime
			Teleport_Players()
		end
	end



function EXIT(player)
	warn("searching char")
	if player.Character then
warn("attempt to leave")
		if player.PlayerGui:FindFirstChild(script.SCENE_GUI.Value.Name) then
			player.PlayerGui:FindFirstChild(script.SCENE_GUI.Value.Name):Destroy()
		end

		player.Character:PivotTo(script.LEAVE_PART.Value.CFrame)
		removeFromList(player.Character)
	end
end

script.Prompt.Value.Triggered:Connect(EXIT)
3 Likes

There is a while loop with no break by the looks of it ( just skimmed through the code)

and how to fix that issue? any samples?

1 Like

wrap it in a coroutine or task.spawn?

1 Like

This will yield your code and prevent your event at the bottom from ever running, so when you press the prompt, your function will not get called.


And if this thing in your script is an instance value, it cannot be touched so this line is probably erroring, also yielding your code.

2 Likes

got the updated code for me? im really bad at implementing my code new

2 Likes