CFrame Error, but shows no error/warnings (REPOST, because no one helped me last post)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make it show after you click join or spawn in button, it would fix the camera to your desired spawn location on the map/game.
  2. What is the issue? Include screenshots / videos if possible!
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried none so far, because there’s no error or warnings shown within the script:

--[[
		 ______   _____ __________    ______   ______
	    / _/ _/  / ___// ____/ __ \_ / ____/  /  /  /
	   / // /    \__ \/ /   / /_/ (_) /_      / // / 
	  / // /    ___/ / /___/ ____/ / __/     / // /  
	 / // /    /____/\____/_/   (_)_/      _/ // /   
	/__/__/                               /__/__/     

	SECURE. CONTAIN. PROTECT 
	SPECIAL CONTAINMENT PROCEDURES.
	
	SCRIPTED BY: O5-8 'The Eclipse'
	
	SCRIPT FUNCTION: Handling player menu tools.
	 
--]]

local event = game.ReplicatedStorage:WaitForChild("MenuTools")
local GroupID = 4219056
local TestService = game:GetService("TestService")


local IntroEnabled = true -- if FALSE, it will enable the maintenence mode.

-- [[ ]] --

if IntroEnabled == false then
	TestService.ExecuteWithStudioRun = false
else
	TestService.ExecuteWithStudioRun = true
end

game.Players.PlayerAdded:connect(function(player)
	if IntroEnabled == true then
		local mainstuff = script.MAINGUI
		local clone = mainstuff:Clone()
		clone.Parent = player.PlayerGui
		clone:FindFirstChild("SCPF_MENU").Disabled = false
	end
	player.CharacterAdded:connect(function(character)
		local humanoid = character:FindFirstChild("Humanoid")
		local team = player.Team
		-- [[ ]] --
		if player:FindFirstChild("ShirtID") then
			for i, v in pairs(player.Character:GetChildren()) do
				if v:IsA("Shirt") or v:IsA("ShirtGraphic") then
					v:Destroy()
				end
			end
			local s = Instance.new("Shirt", player.Character)
			s.ShirtTemplate = "rbxassetid://" .. player:FindFirstChild("ShirtID").Value
		end
		if player:FindFirstChild("PantsID") then
			for i, v in pairs(player.Character:GetChildren()) do
				if v:IsA("Pants") or v:IsA("ShirtGraphic") then
					v:Destroy()
				end
			end
			local p = Instance.new("Pants", player.Character)
			p.PantsTemplate = "rbxassetid://" .. player:FindFirstChild("PantsID").Value
		end
		-- [[ ]] --
		if humanoid then
			-- [[ ]] --
			if humanoid then
				if IntroEnabled == true then
					if not player:FindFirstChild("Loaded") then
						humanoid.WalkSpeed = 0
						humanoid.JumpPower = 0
					end
				end
			end
			-- [[ ]] --
			local teamtools = team:GetChildren()
			print(#teamtools)
			local toolsup = 0
			if #teamtools > 0 then
				for i = 1, #teamtools do
					local tool = teamtools[i]:Clone()
					if tool and tool.Parent ~= player.Backpack then
						tool.Parent = player.Backpack
						toolsup = toolsup + 1
						if toolsup >= #teamtools then
							break
						end
					end
				end
			end
			if IntroEnabled == true then
				if player:FindFirstChild("CELL_NUM") then
					local cdcs = game.Workspace:WaitForChild("CDC_SPAWNS")
					delay(0.1, function()
						local cellname = player:FindFirstChild("CELL_NUM")
						if cellname then
							local cd = cdcs:FindFirstChild("CD" .. cellname.Value)
							local torso = player.Character:FindFirstChild("Torso")
							if torso then
								torso.CFrame = cd.CFrame + Vector3.new(0, 2, 0)
							end
						end
					end)
				end
			end
			-- [[ FUNCTION ]] --
			local function give_card(cardname)
				local cards = game:GetService("ServerStorage"):WaitForChild("CARD_CLEARANCE")
				local cardneeded = cards:FindFirstChild(cardname)
				if cardneeded then
					cardneeded:Clone().Parent = player.Backpack
				end
			end
			local startsentence = "[SCP] Card-"
			-- [[ CARD GIVING ]] --
			if player:GetRoleInGroup(GroupID) == "Level - 0"  then -- L0
				give_card(startsentence .. "L0")
			elseif player:GetRoleInGroup(GroupID) == "Level - 1"  then -- L1
				give_card(startsentence .. "L1")
			elseif player:GetRoleInGroup(GroupID) == "Level - 2" then -- L2
				give_card(startsentence .. "L2")
			elseif player:GetRoleInGroup(GroupID) == "Level - 3"  then -- L3
				give_card(startsentence .. "L3")
			elseif player:GetRoleInGroup(GroupID) == "Level - 4" then -- L4
				give_card(startsentence .. "L4")
			elseif player:GetRoleInGroup(GroupID) == "Level - 5" or player:GetRoleInGroup(GroupID) == "Site Director" then -- L5
				give_card(startsentence .. "L5")
			elseif player:GetRoleInGroup(GroupID) == "O5 Council" or player.UserId == 0 then -- Omni
				give_card(startsentence .. "Omni")
			elseif player:GetRoleInGroup(GroupID) == "O5-X" or player:GetRoleInGroup(GroupID) == "The Administrator" then -- Omni
				give_card(startsentence .. "Omega")
			else -- CD or CE
				if player:GetRoleInGroup(GroupID) == "Class - D" then
					give_card(startsentence .. "CD")
				elseif player:GetRoleInGroup(GroupID) == "Class - E" then
					--give_card(startsentence .. "CE")
				else
					give_card(startsentence .. "CD")
				end
			end
		end
	end)
end)

function OverheadGui(player, visible)
	local character = player.Character
	if player and character then
		local head = character:FindFirstChild("Head")
		local humanoid = character:FindFirstChild("Humanoid")
		if head:FindFirstChild("GiveGUI") then
			local ent = head:FindFirstChild("GiveGUI")
			for i, v in pairs(ent:GetChildren()) do
				v.Visible = visible
			end
		end
	end
end

local InUse = {}
local Entities = 0
local PlayersUse = {}


game.Players.PlayerRemoving:connect(function(player)
	local CPM = "SpawnRoom_" .. player.Name
	if not player:FindFirstChild("Loaded") then
		if workspace:FindFirstChild(CPM) then
			if workspace:FindFirstChild(CPM) then
				workspace:FindFirstChild(CPM):Destroy()
				if Entities > 0 then
					local removal = 0
					local table_pos = 0
					for i, v in pairs(PlayersUse) do
						if player.Name == v then
							table_pos = i
						end
					-- [[ ]] --
					table.remove(InUse, table_pos)
					table.remove(PlayersUse, table_pos)
					Entities = Entities - 1
					-- [[ ]] --
					local r = false
					for i = 1, #InUse do
						if Entities == InUse[i] then
							r = true
						else
							print("None Found")
						end
					end		
					if r == true then
						Entities = Entities - 1
					end	
					-- [[ ]] --
					end
				end
				print("We now have: " .. Entities)
				print("We have: " .. table.concat(InUse, ", ") )
				print("We have players: " .. table.concat(PlayersUse, ", ") )
			end
		end
	end
end)

event.OnServerEvent:connect(function(player, reason, ent)
	if reason == "Teleport" then
		local part = ent
		local torso = player.Character:FindFirstChild("Torso")
		if torso then
			torso.CFrame = part.CFrame + Vector3.new(0, 4, 0) -- this is where it is
		end
	elseif reason == "RemovePackages" then
		for i, v in pairs(player.Character:GetChildren()) do
			if v:IsA("CharacterMesh") then
				v:Destroy()
			end
		end
	elseif reason == "RemoveTP" then
		local CPM = "SpawnRoom_" .. player.Name
		if workspace:FindFirstChild(CPM) then
			if workspace:FindFirstChild(CPM) then
				workspace:FindFirstChild(CPM):Destroy()
				if Entities > 0 then
					local removal = 0
					local table_pos = 0
					for i, v in pairs(PlayersUse) do
						if player.Name == v then
							table_pos = i
						end
					-- [[ ]] --
					table.remove(InUse, table_pos)
					table.remove(PlayersUse, table_pos)
					Entities = Entities - 1
					-- [[ ]] --
					local r = false
					for i = 1, #InUse do
						if Entities == InUse[i] then
							r = true
						else
							print("None Found")
						end
					end		
					if r == true then
						Entities = Entities - 1
					end	
					-- [[ ]] --
					end
				end
				print("We now have: " .. Entities)
				print("We have: " .. table.concat(InUse, ", ") )
				print("We have players: " .. table.concat(PlayersUse, ", ") )
			end
	end
	elseif reason == "AddTP" then
		local object = game.ReplicatedStorage:WaitForChild("SpawnRoom"):Clone()
		local objectcam = object:FindFirstChild("CamPart")
		objectcam.Transparency = 1
		objectcam:FindFirstChild("Cam").Transparency = 1
		object.Name = ent
		object.Parent = game:GetService("Workspace")
		local objectspawn = object:FindFirstChild("PartSpawn")
		objectspawn.Transparency = 1
		local target = 0
		local t = 0
		-- [[ ]] --
		for i = 1, #InUse do
			if Entities == InUse[i] then
				target = Entities + 1
			else
				target = Entities
			end
		end
		-- [[ ]] --
		while t < target do
			for i, v in pairs(object:GetChildren()) do
				v.CFrame = v.CFrame + Vector3.new(-150, 0, 0)
			end
			t = t + 1
			wait()
		end
		wait(0.1)
		table.insert(InUse, Entities)
		table.insert(PlayersUse, player.Name)
		Entities = target + 1
		print("We now have: " .. Entities)
		print("We have: " .. table.concat(InUse, ", ") )
		print("We have players: " .. table.concat(PlayersUse, ", ") )			
	elseif reason == "Freeze" then
		local decide = ent
		if decide == true then
			local char = player.Character
			local humanoid = char:FindFirstChild("Humanoid")
			repeat wait() until humanoid
			humanoid.WalkSpeed = 0
			humanoid.JumpPower = 0
			OverheadGui(player, false)
		else
			local char = player.Character
			local humanoid = char:FindFirstChild("Humanoid")
			repeat wait() until humanoid
			humanoid.WalkSpeed = 16
			humanoid.JumpPower = 50
			OverheadGui(player, true)
		end
	elseif reason == "SetCamAngle" then
		local cameraPart = ent[1]
		local position = ent[2]
		repeat wait() until cameraPart
		cameraPart.CFrame = position
	elseif reason == "NoGUI" then
		local p = player.PlayerGui:FindFirstChild("MAINGUI")
		if p then
			p:Destroy()
		end
	elseif reason == "SetCharAngle" then
		local part = ent
		local char = player.Character
		local humanoid = char:FindFirstChild("Humanoid") 
		if part and part:IsA("Part") then
			if char and humanoid then
				local torso = char:FindFirstChild("Torso")
				local dir = torso.CFrame:pointToObjectSpace(part.Position)
				local spin_y =  math.atan2(dir.x, dir.z) + math.pi
				if torso then
					torso.CFrame = torso.CFrame * CFrame.Angles(0, spin_y, 0)
				end
			end
		end	
	elseif reason == "GiveGUI" then
		local mainstuff = script.MAINGUI
		local clone = mainstuff:Clone()
		clone.Parent = player.PlayerGui
		clone:FindFirstChild("SCPF_MENU").Disabled = false
	elseif reason == "SetTeam" then
		if ent then
		player.Team = ent
		else
		print("could not find team")
		end
	elseif reason == "ReplaceClothing" then
		local SS = ent[1]
		local SP = ent[2]
		print("FiredServer")
		if player then
			for i, v in pairs(player.Character:GetChildren()) do
				if v:IsA("Shirt") or v:IsA("Pants") or v:IsA("Clothing") or v:IsA("ShirtGraphic") then
					v:Destroy()
				end
			end
			local newS = Instance.new("Shirt", player.Character)
			newS.ShirtTemplate = "rbxassetid://" .. SS
			local newP = Instance.new("Pants", player.Character)
			newP.PantsTemplate = "rbxassetid://" .. SP
		end
	elseif reason == "Replace_hat" then
		local hat_model = ent
		if player then
		for i, item in pairs(player.Character:GetChildren()) do
			if item:IsA("Hat") or item:IsA("Accessory") then
				item:Destroy()
			end
		end
		local clone = hat_model:Clone()
		local character_humanoid = player.Character:FindFirstChild("Humanoid")
		character_humanoid:AddAccessory(clone)
		end
	elseif reason == "BodyColors" then
		local color = ent
		if player then
			for i, v in pairs(player.Character:GetChildren()) do
				if v:IsA("BodyColors") then
					local b_c = v
					b_c.HeadColor = color
					b_c.LeftArmColor = color
					b_c.RightArmColor = color
					b_c.LeftLegColor = color
					b_c.RightLegColor = color
					b_c.TorsoColor = color
				end
			end
		end
	elseif reason == "Change_Face" then
		local face_id = "rbxassetid:// " .. ent
		if player then
			if player.Character then
				local head = player.Character:FindFirstChild("Head")
				if head then
					head:FindFirstChild("face").Texture = face_id
				end
			end
		end
	elseif reason == "MakeAmbience" then
		local ambiencesound = script:WaitForChild("Ambience")
		local soundclone = ambiencesound:Clone()
		soundclone.Parent = player.PlayerGui
		soundclone:Play()
	elseif reason == "SetValues" then
		local tab = ent
		-- LAYOUT: {SHIRT_ID, PANTS_ID, FACE, SKIN CLR, HAIR}
		local val = Instance.new("BoolValue", player)
		val.Name = "Loaded"
		-- [[ ]] --
		if tab[1] then
			local val = Instance.new("IntValue", player)
			val.Name = "ShirtID"
			val.Value = tab[1]
			print("C1")
		end
		if tab[2] then
			local val = Instance.new("IntValue", player)
			val.Name = "PantsID"
			val.Value = tab[2]
			print("C2")
		end
		if tab[3] then
			local val = Instance.new("StringValue", player)
			val.Name = "FaceID"
			val.Value = tab[3]
			print("C3")
		end
		if tab[4] then
			local val = Instance.new("BrickColorValue", player)
			val.Name = "SkinColor"
			val.Value = tab[4]
			print("C4")
		end
		if tab[5] then
			local val = Instance.new("ObjectValue", player)
			val.Name = "Hat"
			val.Value = tab[5]
			print("C5")
		end
		if tab[6] then
			local val = Instance.new("BoolValue", player)
			val.Name = "RemovePackages"
			print("C6")
		end
	end
	end)
	
print(script.Name .. "_Loaded.")

Is ent being sent as nil from the client?

Being sent from a Script via ServerScriptService.

Try putting a print(ent) somewhere in there. Does it output nil?

Yeah, sadly… (20 characters)

Whatever LocalScript is firing the event isn’t sending it.


I believe this is firing the event?


“event.OnServerEvent:connect” - firing onto the server, I’m assuming it would

The server is waiting for the event to happen, that’s why it’s .OnServerEvent. :FireServer() can only be fired from the client, so find the part of the LocalScript that’s firing the event.

If your third argument is printing nil, that means that you have nothing in your third argument or whatever was put inside of it does not exist. What are the arguments you are supplying the event with when you fire it?

I don’t think you can use Vector3 with CFrame. Perhaps that is the issue?

local chatGUI = script.Parent.Parent:WaitForChild("ChatGUI")

game.ReplicatedFirst:RemoveDefaultLoadingScreen()
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
local assetgui = script.Parent:WaitForChild("Loading_Assets")
-- [[ ]] --

chatGUI.Enabled = false

local success = false

local event = game.ReplicatedStorage:WaitForChild("MenuTools")
local scpfevents = game.ReplicatedStorage:WaitForChild("Events")

assetgui.Enabled = true

while not success do
	local success, errormsg = pcall(function()
		game:GetService("StarterGui"):SetCore("ResetButtonCallback", false)
		--game:GetService("StarterGui"):SetCore("TopbarEnabled", false)
	end)
	if success then
		print("DONE")
		break
	else
		print("SLOW - " .. errormsg)
	end
	wait()
end


--chatGUI.Enabled = false

local player = game.Players.LocalPlayer
local teamselection = script.Parent:WaitForChild("Team-Selection")
local cutscenescript = teamselection:WaitForChild("SCPF_CUTSCENE")
local readyvalue = teamselection:WaitForChild("Ready")
local mainframe = assetgui:WaitForChild("Loading Assets Frame")
local pop_up = teamselection:WaitForChild("PopUp")

local suitsettings = { -- Table goes as follows: Name, ShirtID, PantsID
	["O5 Council"] = {{"O5 Default", 338740550, 338750779}};
	["[REDACTED]"] = {{"Suit", 338740550, 338750779}};
	["Site Director"] = {{"SiD Suit", 338740550, 338750779}};
	["O5-X"] = {{"O5-X Suit", 888180698, 888180169}};
	["Administrator"] = {{"Administrator Suit", 338740550, 338750779}};
	["Class D"] = {{"Class D Suit", 278872200, 278872148}};
	["Class E"] = {{"Class E Suit", 567501638, 567501404}}; 
	["Foundation Personnel"] = {{"Foundation Personnel", 958267478, 958267659}};
}

local hatstorage = game.ReplicatedStorage:WaitForChild("HatStorage")
local hairsettings = {
	{"[M] Beautiful Black", hatstorage:WaitForChild("MALE-Black")};
	{"[M] Beautiful Blonde", hatstorage:WaitForChild("MALE-Blonde")};
	{"[M] Beautiful Brown", hatstorage:WaitForChild("MALE-Brown")};
	{"[M] Charmer", hatstorage:WaitForChild("MALE-Charmer")};
	{"[M] Blonde Charmer", hatstorage:WaitForChild("MALE-CharmerBlonde")};
	{"[M] Blue Charmer", hatstorage:WaitForChild("MALE-CharmerBlue")};
	{"[F] Long Black", hatstorage:WaitForChild("FEMALE-Black")};
	{"[F] Long Blonde", hatstorage:WaitForChild("FEMALE-Blonde")};
	{"[F] Long Brown", hatstorage:WaitForChild("FEMALE-Brown")};
	{"[F] Anime Hair", hatstorage:WaitForChild("FEMALE-Anime")};
}

local facesettings = {
	{"Skeptic", 150545226};
	{"Shiny", 708214657};
	{"Whistle", 228054851};
	{"Suspicious", 210559531};
	{"Bored", 136512852};
	{"Err", 155195214};
	{"Ankward Grin", 150374839}
}

local skinsettings = {
	{"Pale", BrickColor.new("Pastel brown")};
	{"Light-Tinted", BrickColor.new("Light orange")};
	{"Tinted" , BrickColor.new("Nougat")};
	{"Brown", BrickColor.new("Brown")}
	
}

--local suitsettings, hairsettings, facesettings, skinsettings = require(script.Parent.CharacterCustomization)
--local moduleAPI = require(script.Parent:WaitForChild("Module3D"))

-- [[ TEAM SETTINGS ]] --

local team_settings = { -- [[ FORMAT: USERID ]] --
	["Class E"] = {447221885};
	["O5-1"] = {123675221};
	["O5-2"] = {177122625};
	["O5-3"] = {47660361}; -- 47660361 - Wolfiyon | 
	["O5-4"] = {106096208}; -- 106096208
	["O5-5"] = {0}; -- 285309339
	["O5-6"] = {31368462};
	["O5-7"] = {3805018};
	["O5-8"] = {60221060}; -- 60221060
	["O5-9"] = {126423302};
	["O5-10"] = {126900660};
	["O5-11"] = {83038669};
	["O5-12"] = {84732423};
	["O5-13"] = {434036932};
	["O5-X"] = {285309339}; -- 285309339 - Job
	["Site Director"] = {21990767, 687196616};
	["Administrator"] = {720548616};
	["SpecialPeople"] = {75540511};
}

local music_settings = { -- [[ FORMAT: MUSICID ]] --
	{"iiSxnic", 916438756, 1571842475};
}

local O5_teamlist = { -- [[ FORMAT: TEAMNAME
	["O5-1"] = {"Mobile Task Force"};
	["O5-2"] = {"Internal Security Department"};
	["O5-3"] = {"Department Of External Affairs"};
	["O5-4"] = {"Engineering & Technical"};
	["O5-5"] = {"Scientific Department"};
	["O5-6"] = {"Ethics Committee"};
	["O5-7"] = {"Security Department"};
	["O5-8"] = {"Manufacturing Department"};
	["O5-9"] = {"Medical Department"};
	["O5-10"] = {"Intelligence Agency"};
	["O5-11"] = {"Rapid Response Team"};
	["O5-12"] = {"[DATA EXPUNGED]"};
	["O5-13"] = {"O5C"};
	["O5-X"] = {"Administrative Department"}; -- TEMP.
	["Site Director"] = {"Manufacturing Department"};
	["Administrator"] = {"The Administrator"};
	["SpecialPeople"] = {"[REDACTED]"};
}


-- [[ ]]

local contentprovider = game:GetService("ContentProvider")
local server_event = game.ReplicatedStorage:WaitForChild("GUIFunctions")

local canClick = false

local selectedTeam = nil

local hoversound = teamselection:WaitForChild("MouseHover")
local clicksound = teamselection:WaitForChild("Click")
local noaccess = teamselection:WaitForChild("NoAccess")
local swooshsound = teamselection:WaitForChild("Swoosh")

-- [[ Handling functions ]] --

function FadeText(obj)
	coroutine.resume(coroutine.create(function()
		for i = obj.TextTransparency, 1.05, 0.01 do
			obj.TextTransparency = i
			wait()
		end
	end))
end

local logoRot = true

coroutine.resume(coroutine.create(function()
	--[[
	local logo = mainframe:FindFirstChild("S.C.P.F. Logo")
	if logo then
		local full_time = 1
		while logoRot == true do
			logo.Rotation = logo.Rotation + 4
			if logo.Rotaion >= (360 * full_time) then
				full_time = full_time + 1
			end
			wait()
		end
		while true do
			logo.Rotation = logo.Rotation + 2
			if logo.Rotation >= (359 * full_time) then
				break
			end
			wait()
		end
		logo.Rotation = 360 * full_time
	end
	]]--
end))

function HandleIntro()
	logoRot = true
	-- [[]] --
	local logo = mainframe:FindFirstChild("S.C.P.F. Logo")
	local totalassets = tonumber(contentprovider.RequestQueueSize)
	local storednumber = totalassets
	--[[]]--
	local percentagetext = mainframe:WaitForChild("Percentage")
	local assettext = mainframe:WaitForChild("AssetText")
	local assetdesc = mainframe:WaitForChild("assets-desc.")
	local credit = mainframe:WaitForChild("Credit")
	local op1 = mainframe:WaitForChild("S.C.P.F. Text-Found.")
	local op2 = mainframe:WaitForChild("S.C.P.F. Text-Sec.")
	
	--[[]]--
	assettext.Text = "Preparing to load.."
	wait(2)
	repeat wait() until game.Loaded
	assettext.Text = "Loading assets."
	repeat
		local remaining = contentprovider.RequestQueueSize
		local pie = (storednumber - remaining)
		local percentage = math.floor(100 / storednumber * pie)
		percentagetext.Text = ((percentage < 0 and "0") or percentage) .. " %"
		percentagetext:FindFirstChild("AssetsLeft").Text = "Remaining: " .. remaining
		wait()
	until remaining <= 0
	logoRot = false
	assettext.Text = "Loading finished."
	percentagetext.Text = "100 %"
	percentagetext:FindFirstChild("AssetsLeft").Text = "finished."
	assetdesc.Visible = false
	credit.Visible = false
	wait(.5)
	FadeText(op1)
	FadeText(op2)
	FadeText(percentagetext)
	FadeText(percentagetext:FindFirstChild("AssetsLeft"))
	FadeText(assettext)
	wait(4)
	logo:TweenPosition(UDim2.new(0.5, 0, -.5, 0), "InOut", "Quint", 4)
	wait(3.5)
	cutscenescript.Disabled = false
	local mId = 168146979
	local vol = 0.25
	for i = 1, #music_settings do
		if player.Name == music_settings[i][1] then
			mId = music_settings[i][math.random(2, #music_settings[i])]
			vol = 0.5
			print("True")
		end
	end
	script.Parent.ScaryMusic.SoundId = "rbxassetid://" .. mId
	script.Parent.ScaryMusic:Play()
	script.Parent.ScaryMusic.Volume = vol
	for i = 0, 1.05, 0.01 do
		mainframe.BackgroundTransparency = i
		wait()
	end
end

local choosefunc = teamselection:WaitForChild("ChooseFunction")
local logo = teamselection:WaitForChild("LogoFirst")
local moduleframe = teamselection:WaitForChild("Module3D_Frame")

local appbtn = choosefunc:WaitForChild("AppBTN")
local helpbtn = choosefunc:WaitForChild("HelpBTN")
local playbtn = choosefunc:WaitForChild("PlayBTN")

-- [[ PAGE 1 ]] --

local page1 = teamselection:WaitForChild("Page1")
local teamchoose = page1:WaitForChild("TeamChoose")
local suitchoose = page1:WaitForChild("SuitChoose")
local teamR = page1:WaitForChild("T>")
local teamL = page1:WaitForChild("<T")
local suitR = page1:WaitForChild("S>")
local suitL = page1:WaitForChild("<S")
local nextBtn1 = page1:WaitForChild("NextBTN")
local backBtn1 = page1:WaitForChild("BackBTN")

-- [[ PAGE 2 ]] --

local page2 = teamselection:WaitForChild("Page2")
local facechoose = page2:WaitForChild("FaceChoose")
local hairchoose = page2:WaitForChild("HairChoose")
local skinchoose = page2:WaitForChild("SkinChoose")
local faceR = page2:WaitForChild("F>")
local faceL = page2:WaitForChild("<F")
local hairR = page2:WaitForChild("H>")
local hairL = page2:WaitForChild("<H")
local skinR = page2:WaitForChild("S>")
local skinL = page2:WaitForChild("<S")
local joinBtn2 = page2:WaitForChild("JoinBTN")
local backBtn2 = page2:WaitForChild("BackBTN")

-- [[ CREDIT ]] --

local helpcredit = teamselection:WaitForChild("Help+Credit")

-- [[ HR ]] --

local Curr_name = nil

-- [[ Cherker ;) ]] --

function checkTable(finding, list)
	for i = 1, #list do
		if finding == list[i] then	
			return true
		else
			return false
		end
	end
end

-- [[ Checking HR ]] --
local ifHR = nil
local ifL4 = false

if checkTable(player.UserId, team_settings["O5-1"]) then
	ifHR = "O5-1"
elseif checkTable(player.UserId, team_settings["O5-2"]) then
	ifHR = "O5-2"
elseif checkTable(player.UserId, team_settings["O5-3"]) then
	ifHR = "O5-3"
elseif checkTable(player.UserId, team_settings["O5-4"]) then
	ifHR = "O5-4"
elseif checkTable(player.UserId, team_settings["O5-5"]) then
	ifHR = "O5-5"
elseif checkTable(player.UserId, team_settings["O5-6"]) then
	ifHR = "O5-6"
elseif checkTable(player.UserId, team_settings["O5-7"]) then
	ifHR = "O5-7"
elseif checkTable(player.UserId, team_settings["O5-8"]) then
	ifHR = "O5-8"
elseif checkTable(player.UserId, team_settings["O5-9"]) then
	ifHR = "O5-9"
elseif checkTable(player.UserId, team_settings["O5-10"]) then
	ifHR = "O5-10"
elseif checkTable(player.UserId, team_settings["O5-11"]) then
	ifHR = "O5-11"
elseif checkTable(player.UserId, team_settings["O5-12"]) then
	ifHR = "O5-12"
elseif checkTable(player.UserId, team_settings["O5-13"]) then
	ifHR = "O5-13"
elseif checkTable(player.UserId, team_settings["O5-X"]) then
	ifHR = "O5-X"
elseif checkTable(player.UserId, team_settings["Site Director"]) then
	ifHR = "Site Director"
elseif checkTable(player.UserId, team_settings.Administrator) then
	ifHR = "Administrator"
elseif checkTable(player.UserId, team_settings["SpecialPeople"]) then
	ifHR = "SpecialPeople"
else
	ifHR = nil
end

local teamList = {} -- Please leave this one empty.
local teamIndex = 1
local suitIndex = 1
local hairIndex = 1
local faceIndex = 1
local skinIndex = 1

local selectedSuit = nil
local selectedSuitShirt = nil
local selectedSuitPants = nil

local selectedHair = nil
local selectedFace = nil
local selectedSkinColor = nil

function detect_classD()
	-- [SET] --
	local groupID_Main = 4219056
	-- [[ ]] --
	local v = 0
	for i, plr in pairs(game.Players:GetChildren()) do
		if plr:GetRankInGroup(groupID_Main) >= 1 and plr:GetRankInGroup(groupID_Main) < 3 then
			v = v + 1
		end
	end
	local cdm = choosefunc:FindFirstChild("CD/FP-Amount")
	if v <= 0 then
		cdm.Text = "NONE."
	else
		cdm.Text = v
	end
end

if player:GetRankInGroup(4219056) == 9 then
	for i, v in pairs(team_settings["Site Director"]) do
		if v ~= player.UserId then
			table.insert(team_settings["Site Director"], player.UserId)
		end
	end
end

function instert_teams()
	-- [[ SETTINGS ]] --
	local groupID_Main = 4219056
	-- [[ DEPARTMENTS ]] -- 
	local groupID_ScD = 00
	local groupID_MTF = 00
	local groupID_MD = 00
	local groupID_SD = 00
	local groupID_MaD = 00
	local groupID_EC = 0
	local groupID_IsD = 00
	local groupID_DEA = 00
	local groupID_IA = 00
	local groupID_ET = 000
	local groupID_DATA_EXPUNGED = 000
	-- [[ Function ]] --
	if player:IsInGroup(groupID_Main) then
		if not checkTable(player.UserId, team_settings["Class E"]) then
			-- [[ Player is not Class E ]] --
			if ifHR ~= nil then
				if ifHR ~= "O5-X" then
				if ifHR ~= "SpecialPeople" then
					table.insert(teamList, "O5 Council")
				end
				-- [[ Adding their suits to the list ]] --
				if ifHR == "O5-1" then
					
				elseif ifHR == "O5-2" then
					
				elseif ifHR == "O5-3" then
					
				elseif ifHR == "O5-4" then
					-- for O5-4.
					table.insert(suitsettings["O5 Council"], {"E&T Overseer", 1098940399, 1098940940})
				elseif ifHR == "O5-5" then
					table.insert(suitsettings["O5 Council"], {"O5-5 MaD suit", 423346027, 423346190})
					table.insert(suitsettings["O5 Council"], {"Researcher suit", 1083270421, 1083270860})
				elseif ifHR == "O5-6" then
					
				elseif ifHR == "O5-7" then
					
				elseif ifHR == "O5-8" then
					-- For iiSxnic. 
					table.insert(suitsettings["O5 Council"], {"MaD Overseer", 422185939, 422185573})
				elseif ifHR == "O5-9" then
					
				elseif ifHR == "O5-10" then
					
				elseif ifHR == "O5-11" then
					
				elseif ifHR == "O5-12" then
					
				elseif ifHR == "SpecialPeople" then
					table.insert(teamList, "[REDACTED]")
				elseif ifHR == "Site Director" then
					table.insert(teamList, "Site Director")
				end
				else
				table.insert(teamList, "O5-X")	
					-- For Wolfiyon. 
				table.insert(suitsettings["O5-X"], {"O5-X Suit2", 2102372829, 2102374558})
				end
			elseif player:GetRankInGroup(groupID_Main) == 9 then
				table.insert(teamList, "Site Director")
			elseif player:GetRankInGroup(groupID_Main) == 255 then
				table.insert(teamList, "Administrator")
			elseif player:GetRankInGroup(groupID_Main) > 00 and player:GetRankInGroup(groupID_Main) < 255 then
				-- [[ All teamz ]] --
				if player:GetRankInGroup(groupID_ScD) > 1 then
					table.insert(teamList, "Scientific Department")
				elseif player:GetRankInGroup(groupID_MTF) > 1 then
					table.insert(teamList, "Mobile Task Force")
				elseif player:GetRankInGroup(groupID_MD) > 1 then	
					table.insert(teamList, "Medical Department")				
				elseif player:GetRankInGroup(groupID_SD) > 1 then
					table.insert(teamList, "Security Department")
				elseif player:GetRankInGroup(groupID_MaD) > 1 then
					table.insert(teamList, "Manufacturing Department")
				elseif player:GetRankInGroup(groupID_EC) > 1 then
					table.insert(teamList, "Ethics Committee")
				elseif player:GetRankInGroup(groupID_IsD) > 1 then
					table.insert(teamList, "Internal Seucurity Department")
				elseif player:GetRankInGroup(groupID_DEA) > 1 then
					table.insert(teamList, "Department Of External Affairs")
				elseif player:GetRankInGroup(groupID_IA) > 1 then
					table.insert(teamList, "Intelligence Agency")
				elseif player:GetRankInGroup(groupID_ET) > 1 then
					table.insert(teamList, "Engineering & Technical")
					-- [[ SHIRT SETTINGS ]] --
					if player:GetRoleInGroup(groupID_ET) == "Intern" then
						table.insert(suitsettings["Engineering & Technical"], {"Intern", 1098935971, 1098940940})
					elseif player:GetRoleInGroup(groupID_ET) == "Tech" then
						table.insert(suitsettings["Engineering & Technical"], {"Engineer", 1098936146, 1098940940})
					elseif player:GetRoleInGroup(groupID_ET) == "Electrical Engineer" then
						table.insert(suitsettings["Engineering & Technical"], {"Engineer", 1098936146, 1098940940})
					elseif player:GetRoleInGroup(groupID_ET) == "Senior Engineer" then
						table.insert(suitsettings["Engineering & Technical"], {"Senior Engineer", 1098936275, 1098940940})
					elseif player:GetRoleInGroup(groupID_ET) == "Supervisor" then
						table.insert(suitsettings["Engineering & Technical"], {"Chief Engineer", 1098939984, 1098940940})
					elseif player:GetRoleInGroup(groupID_ET) == "Assistant Director" then
						table.insert(suitsettings["Engineering & Technical"], {"Director Engineer", 1098940159, 1098940940})
					elseif player:GetRoleInGroup(groupID_ET) == "Director" then	
						table.insert(suitsettings["Engineering & Technical"], {"Director Engineer", 1098940159, 1098940940})
					end
					-- [[ ]]
				elseif player:GetRankInGroup(groupID_DATA_EXPUNGED) > 1 then
					table.insert(teamList, "[DATA EXPUNGED]")
				else
					table.insert(teamList, "Foundation Personnel")
				end
			elseif player:GetRankInGroup(groupID_Main) == 2 and player:GetRankInGroup(groupID_Main) < 3 then
				table.insert(teamList, "Class E")	
			elseif player:GetRankInGroup(groupID_Main) == 1 and player:GetRankInGroup(groupID_Main) < 2 then
				table.insert(teamList, "Class D")
			end
			if player:GetRankInGroup(groupID_Main) >= 7 then
				ifL4 = true
				print(player.Name .. " is L4+")
			end
		else
			table.insert(teamList, "Class E")	
		end
	else
		table.insert(teamList, "Class D")		
	end
end

function updateSuit(teamname, table_index)
	local findtable = suitsettings[teamname]
	local getlist = findtable[table_index]
	if findtable and getlist then
		print("NAME: " .. getlist[1] .. ", SHIRTID: " .. getlist[2] .. ", PANTSID: " .. getlist[3])
		return getlist[1], getlist[2], getlist[3]
	end
end

function updateHair(table_index)
	local findtable = hairsettings[table_index]
	if findtable then
		print("HATNAME: " .. findtable[1])
		return findtable[1], findtable[2]
	end
end

function updateFace(table_index)
	local findtable = facesettings[table_index]
	if findtable then
		print("FACENAME: " .. findtable[1])
		return findtable[1], findtable[2]
	end
end

function updateSkinColor(table_index)
	local findtable = skinsettings[table_index]
	if findtable then
		print("SKINNAME: " .. findtable[1])
		return findtable[1], findtable[2]
	end
end

--[[
function replaceHat(hat)
	local character = nil
	for i, object in pairs(game.Workspace.CurrentCamera:GetChildren()) do
		if object:FindFirstChild("Humanoid") then
			character = object
			for i, v in pairs(object:GetChildren()) do
				print("ObjectName: " .. v.Name)
			end
		end
	end
	repeat wait() until character
	print("Character found: Objectname: `" .. character.Name .. "`")
	for i, item in pairs(character:GetChildren()) do
		if item:IsA("Hat") then
			item:Destroy()
		end
	end
	local find_hat = hat
	find_hat:Clone().Parent = character
]]--

local pointName = "SpawnRoom_" .. player.Name

local cameraSuccess = false
while cameraSuccess == false do
--
cameraSuccess, failmsg = pcall(function() 
	-- [[ WAITING FOR CHARACTER ]] --
	repeat wait() until player and player.Character
	repeat wait() until player.Character:IsDescendantOf(workspace)
	local currentcam = workspace.CurrentCamera
	--server_event:Fire(player, "Attach_Character", currentcam)
	event:FireServer("AddTP", pointName)
	wait(1)
	local getp = workspace:FindFirstChild(pointName)
	if getp ~= nil then
		event:FireServer("Teleport", getp:FindFirstChild("PartSpawn"))
		event:FireServer("Freeze", true)
	else
		warn("WARNING - NIL")
	end
end)
--
end

wait(1)

--[[
local CP = workspace:FindFirstChild(pointName):FindFirstChild("CamPart")
if CP ~= nil then
	print("CP = NOT NIL")
	local dif = player.Character.Head.CFrame + Vector3.new(0.75, 0, -10)
	local enteties = {CP, dif}
	local enteties2 = {CP.Cam, (dif + Vector3.new(0, 0, 1))}
	event:FireServer("SetCamAngle",enteties)
	event:FireServer("SetCamAngle",enteties2)
else
	print("CP = NIL")
end
]]--

wait(1)

function HandleStartup()
	-- [[ Checking for HR first. ]] --
	local typwriter = teamselection:WaitForChild("Typr")
	local text = "SITE - 112"
	local welcometext = choosefunc:WaitForChild("Welcome")
	if checkTable(player.UserId, team_settings["Class E"]) == false then
		print(player.Name .. " is not class E")
		if ifHR ~= nil then
			Curr_name = ifHR
		else
			Curr_name = player.Name
		end
	else
		Curr_name = player.Name
	end
	typwriter.Visible = true
	for i = 1, #text do
		typwriter.Text = string.sub(text, 1, i)
		wait(.5)
	end
	typwriter:FindFirstChild("Line").Visible = true
	typwriter:FindFirstChild("Line"):TweenSize(UDim2.new(0.235, 0, 0.006, 0), "Out", "Quint", 2)
	wait(2)
	FadeText(typwriter)
	wait(1)
	spawn(function()
		print("F1")
		local darken = teamselection:WaitForChild("Darken")
		darken.BackgroundTransparency = 1
		darken.Visible = true
		while darken.BackgroundTransparency > 0 do
			darken.BackgroundTransparency = darken.BackgroundTransparency - 0.035
			wait()
		end
	end)
	wait(2)
	typwriter:FindFirstChild("Line"):TweenSize(UDim2.new(0, 0, 0.006, 0), "Out", "Quint", 2)
	wait(1)
	logo.Position = UDim2.new(-1, 0, 0, 0)
	logo.Visible = true
	logo:TweenPosition(UDim2.new(0, 0, 0, 0), "Out", "Quint", 3)
	wait(1)
	
	typwriter:FindFirstChild("Line").Visible = false
	local positions = {}
	for i, frame in pairs(choosefunc:GetChildren()) do
		if frame then
			table.insert(positions, frame.Position)
			wait(.001)
			frame.Position = frame.Position + UDim2.new(-1, 0, 0, 0)
		end
	end
	choosefunc.Position = choosefunc.Position + UDim2.new(-1, 0, 0, 0)
	choosefunc.Visible = true
	choosefunc:TweenPosition(UDim2.new(0.025, 0, 0.23, 0), "Out", "Quint", 3)
	instert_teams()
	detect_classD()
	wait(1)
	moduleframe.Position = moduleframe.Position + UDim2.new(1, 0, 0, 0)
	
		-- [[ Finding suits, face, hair etc ]] --
			local suitname, suitShirt, suitPants = updateSuit(teamList[1], 1)
			suitchoose:FindFirstChild("TextLabel").Text = suitname
			-- [[ Let's go and put in the values! ]] --
			selectedSuit = suitchoose
			selectedSuitShirt = suitShirt
			selectedSuitPants = suitPants
			-- [[ Hair ]] --
			if not ifL4 then
			local hairname, hairmodel = updateHair(1)
			selectedHair = hairname
			
			event:FireServer("Replace_hat", hairmodel)
			
			local facename, faceID = updateFace(1)
			local skin_name, skinColor = updateSkinColor(1)
			print(facename .. " || " .. faceID)
			
			event:FireServer("BodyColors", skinColor)
				
			event:FireServer("Change_Face", faceID)
			
			event:FireServer("RemovePackages", nil)
			
			else
				
			
			
			end
			
		-- [[ Getting them ]] --
		
		event:FireServer("ReplaceClothing", {selectedSuitShirt, selectedSuitPants})
		
		-- [[ Greeting and other stuff ]] --
	welcometext.Text = "Welcome, " .. Curr_name .. "!"
	moduleframe:TweenPosition(UDim2.new(0.65, 0, 0.5, 0), "Out", "Quint", 2)
	cutscenescript.Disabled = true
	wait(0.05)
	local camera = game.Workspace.CurrentCamera
	local partfocus = workspace:FindFirstChild(pointName):FindFirstChild("CamPart")
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CameraSubject = partfocus
	event:FireServer("SetCharAngle", partfocus)
	camera:Interpolate(partfocus.CFrame, partfocus:FindFirstChild("Cam").CFrame, 3)
	
	coroutine.resume(coroutine.create(function()
		local findblur = game.Workspace.CurrentCamera:WaitForChild("Blur")
		if findblur then
			while findblur.Size > 0 do
				findblur.Size = findblur.Size - 0.5
				wait()
			end
		end
	end))
	delay(3, function()
		print("F2")
		local darken = teamselection:WaitForChild("Darken")
		darken.BackgroundTransparency = 0
		while darken.BackgroundTransparency < 1 do
			darken.BackgroundTransparency = darken.BackgroundTransparency + 0.01
			wait()
		end
		darken.Visible = true
	end)
	delay(4, function()
		local chosen = false
		local indexlist = 0
		for i = 1, #music_settings do
			if player.Name == music_settings[i][1] then
				chosen = true
				indexlist = i
			end
		end
		if chosen then
			local m = teamselection:WaitForChild("NowPlaying")
			local subbedasset = string.sub(tostring(script.Parent.ScaryMusic.SoundId), 14)
			print("Subbed asset: " .. subbedasset)
			local product_info = game:GetService("MarketplaceService"):GetProductInfo( tonumber(subbedasset) )
			m:TweenPosition(UDim2.new(0.4, 0, 0.8, 0), "Out", "Quint", 2)
			m.TextLabel.Text = ""
			wait(1)
			m.TextLabel.Text = "Now playing: " .. product_info.Name
			m.TextLabel.Position = UDim2.new(1, 0, 0, 0)
			m.TextLabel:TweenPosition(UDim2.new(-1, 0, 0, 0), "Out", "Linear", 8)
			wait(8)
			m:TweenPosition(UDim2.new(0.4, 0, 1.4, 0), "InOut", "Quint", 2)
		end
	end)
	for i, frame in pairs(choosefunc:GetChildren()) do
		if frame then
			frame:TweenPosition(positions[i], "Out", "Quint", 2)
			wait(.3)
		end
	end
	wait(.6)
	canClick = true
end

-- [[ More Functions ]] --

for _, btn in pairs(choosefunc:GetChildren()) do
	if btn:IsA("TextButton") then
		btn.MouseEnter:connect(function()
			if canClick then
			hoversound:Play()
			btn_line(btn, true)
			end
		end)
		btn.MouseLeave:connect(function()
			if canClick then
			btn_line(btn, false)
			end
		end)
	end
end

for _, btn in pairs(page1:GetChildren()) do
	if btn:IsA("TextButton") then
		btn.MouseEnter:connect(function()
			if canClick then
			hoversound:Play()
			btn_line(btn, true)
			end
		end)
		btn.MouseLeave:connect(function()
			if canClick then
			btn_line(btn, false)
			end
		end)
	end
end

for _, btn in pairs(page2:GetChildren()) do
	if btn:IsA("TextButton") then
		btn.MouseEnter:connect(function()
			if canClick then
			hoversound:Play()
			btn_line(btn, true)
			end
		end)
		btn.MouseLeave:connect(function()
			if canClick then
			btn_line(btn, false)
			end
		end)
	end
end

pop_up:FindFirstChild("CUST").MouseEnter:connect(function()
	if canClick then
		hoversound:Play()
		btn_line(pop_up:FindFirstChild("CUST"), true)
	end
end)
pop_up:FindFirstChild("CUST").MouseLeave:connect(function()
	if canClick then
		btn_line(pop_up:FindFirstChild("CUST"), false)
	end
end)
pop_up:FindFirstChild("DEF").MouseEnter:connect(function()
	if canClick then
		hoversound:Play()
		btn_line(pop_up:FindFirstChild("DEF"), true)
	end
end)
pop_up:FindFirstChild("DEF").MouseLeave:connect(function()
	if canClick then
		btn_line(pop_up:FindFirstChild("DEF"), false)
	end
end)
-- [[ ]] --
helpcredit:FindFirstChild("BackBTN").MouseEnter:connect(function()
	if canClick then
		hoversound:Play()
		btn_line(helpcredit:FindFirstChild("BackBTN"), true)
	end
end)
helpcredit:FindFirstChild("BackBTN").MouseLeave:connect(function()
	if canClick then
		btn_line(helpcredit:FindFirstChild("BackBTN"), false)
	end
end)

-- [[ ]] --

function btn_line(button, onoff)
	local TWT = 0.25
	coroutine.resume(coroutine.create(function()
	if onoff == true then
		local done = false
		if not done then
		button:FindFirstChild("Sign").Visible = true
		button:FindFirstChild("Sign"):TweenSize(UDim2.new(1, 0, 0, 0.02), "Out", "Quint", TWT, false, nil)
		wait(TWT)
		button:FindFirstChild("Sign").Size = UDim2.new(1, 0, 0, 0.02)
		done = true
		end
	else
		local done = false
		if not done then
		button:FindFirstChild("Sign"):TweenSize(UDim2.new(0, 0, 0, 0.02), "Out", "Quint", TWT, false, nil)
		wait(TWT)
		button:FindFirstChild("Sign").Size = UDim2.new(0, 0, 0, 0.02)
		button:FindFirstChild("Sign").Visible = false
		done = true
		end
	end
	end))
end

function main_dissapear(objectpart)
	local positions = {}
		for i, frame in pairs(objectpart:GetChildren()) do
			if frame then
				table.insert(positions, frame.Position + UDim2.new(-1, 0, 0, 0))
			end
		end
		for i, frame in pairs(objectpart:GetChildren()) do
			if frame then
				frame:TweenPosition(positions[i], "Out", "Quint", 2)
				wait(.3)
			end
		end
		wait(0.3)
		objectpart:TweenPosition(UDim2.new(0.025 - 1, 0, 0.23, 0), "InOut", "Quint", 3, false, nil)
end



function Handle_Ending()
	coroutine.resume(coroutine.create(function()
	local humanoid = player.Character:FindFirstChild("Humanoid")
	local torso = player.Character:FindFirstChild("Torso")
	coroutine.resume(coroutine.create(function()
		print("F3")
		local d = teamselection:WaitForChild("Darken")
		local t = 1
		d.Visible = true
		d.BackgroundTransparency = 1
		while t > 0 do
			t = t - 0.05
			d.BackgroundTransparency = t
			wait()
		end
	end))
	if humanoid then
	local camera = game.Workspace.CurrentCamera
	local focus = humanoid
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CameraSubject = humanoid
	camera:Interpolate(torso.CFrame, player.Character:FindFirstChild("Head").CFrame, 4.5)
	wait(5.5 / 2)
	if teamList[teamIndex] == "Class D" then
		delay(1, function()
			scpfevents:FireServer("PrepareCD")
			wait(0.1)
			scpfevents:FireServer("TPCD")
		end)
	end
	wait(5.5 / 2)
	camera.CameraType = Enum.CameraType.Custom
	coroutine.resume(coroutine.create(function()
		print("F4")
		local d = teamselection:WaitForChild("Darken")
		local t = 0

		d.BackgroundTransparency = 0
		while t < 1 do
			t = t + 0.05
			d.BackgroundTransparency = t
			wait()
		end
		d.Visible = false
		-- important
		game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
		game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
		game:GetService("StarterGui"):SetCore("TopbarEnabled", true)
		chatGUI.Enabled = true
		-- haha
		event:FireServer("MakeAmbience")
		event:FireServer("NoGUI")
	end))
	end
	end))
end

function moveList(listname, text)
	local textInside = listname:FindFirstChild("TextLabel")
	if textInside then
		coroutine.resume(coroutine.create(function()
		textInside:TweenPosition(UDim2.new(1, 0, 0, 0), "Out", "Quint", 0.5)
		wait(0.5)
		textInside.Position = UDim2.new(-1, 0, 0, 0)
		textInside.Text = text
		textInside:TweenPosition(UDim2.new(0, 0, 0, 0), "Out", "Quint", 0.5)
		end))
	end
end

-- [[ Events ]] --

local creditframe = helpcredit:WaitForChild("CreditFrame")
local logoV = helpcredit:WaitForChild("Logo")
local backbutton_help = helpcredit:WaitForChild("BackBTN")

-- [[ PLAYING BUTTONS ]] --

function do_main()
	local pos_frames = {}
		for i, v in pairs(page1:GetChildren()) do
			table.insert(pos_frames, v.Position)
			if v.Name == "<S" or v.Name == "<T" or v.Name == "BackBTN" or v.Name == "TextLabel" then
				v.Position = v.Position + UDim2.new(-1, 0, 0, 0)
			elseif v.Name == "S>" or v.Name == "T>" or v.Name == "NextBTN" then
				v.Position = v.Position + UDim2.new(1, 0, 0, 0)
			elseif v.Name == "TeamChoose" then
				v.Position = v.Position + UDim2.new(0, 0, -1, 0)
			else
				v.Position = v.Position + UDim2.new(0, 0, 1, 0)
			end
		end
		page1.Position = page1.Position + UDim2.new(-1, 0, 0, 0)
		
		page1.Visible = true
		page1:TweenPosition(UDim2.new(0.025, 0, 0.23, 0), "Out", "Quint", 2)
		wait(1)
		for i, frame in pairs(page1:GetChildren()) do
			if frame then
				frame:TweenPosition(pos_frames[i], "Out", "Quint", 2)
				wait(.3)
			end
		end
		wait(.3)
	canClick = true
end

function do_mainP2()
	local pos_frames = {}
		for i, v in pairs(page2:GetChildren()) do
			table.insert(pos_frames, v.Position)
			if v.Name == "<S" or v.Name == "<H" or v.Name == "<F" or v.Name == "BackBTN" or v.Name == "TextLabel" then
				v.Position = v.Position + UDim2.new(-1, 0, 0, 0)
			elseif v.Name == "S>" or v.Name == "H>" or v.Name == "F>" or v.Name == "JoinBTN" then
				v.Position = v.Position + UDim2.new(1, 0, 0, 0)
			elseif v.Name == "HairChoose" then
				v.Position = v.Position + UDim2.new(0, 0, -1, 0)
			else
				v.Position = v.Position + UDim2.new(0, 0, 1, 0)
			end
		end
		page2.Position = page1.Position + UDim2.new(-1, 0, 0, 0)
		
		page2.Visible = true
		page2:TweenPosition(UDim2.new(0.025, 0, 0.23, 0), "Out", "Quint", 2)
		wait(1)
		for i, frame in pairs(page2:GetChildren()) do
			if frame then
				frame:TweenPosition(pos_frames[i], "Out", "Quint", 2)
				wait(.3)
			end
		end
		wait(.3)
	canClick = true
	print("True")
end

playbtn.MouseButton1Click:connect(function()
	if canClick then
		clicksound:Play()
		canClick = false
		main_dissapear(choosefunc)
		print("TEAMS: " .. table.concat(teamList, ", "))
		if #teamList > 0 then
			teamchoose:FindFirstChild("TextLabel").Text = teamList[1]
			local suitname, suitShirt, suitPants = updateSuit(teamList[1], 1)
			suitchoose:FindFirstChild("TextLabel").Text = suitname
			-- [[ Let's go and put in the values! ]] --
			selectedSuit = suitchoose
			selectedSuitShirt = suitShirt
			selectedSuitPants = suitPants
		end
		choosefunc:TweenPosition(UDim2.new(-1, 0, 0.23, 0), "Out", "Quint", 2, false)
		wait(1.5)
		choosefunc.Visible = false
		if ifL4 == true then
		page1:WaitForChild("Texto").Text = 'All done? Press the → to join the game!'
		pop_up.Position = UDim2.new(2, 0, 0.5, 0)
		pop_up:TweenPosition(UDim2.new(0.6, 0, 0.5, 0), "Out", "Quint", 2, false)
		pop_up.Visible = true
		wait(0.25)
		swooshsound:Play()
		wait(1.75)
		canClick = true
		else
			page1:WaitForChild("Texto").Text = 'Press → to continue.'
			do_main()
		end
		-- [[ ]] --
	end
end)

local custed = false

pop_up:FindFirstChild("CUST").MouseButton1Click:connect(function()
	if canClick then
	custed = true -- Makes sure that a value turns true that you want to customize.
	-- [[ This function is called when the customize button is clicked. ]] --
			local hairName, hairmodel = updateHair(1)
			-- [[ Make sure to edit the list as well.. ]] --
			selectedHair = hairmodel
			
			
			local facename, faceID = updateFace(1)
			local skin_name, skinColor = updateSkinColor(1)
			print(facename .. " || " .. faceID)
			
			wait(0.01)
			event:FireServer("Replace_hat", hairmodel)	
			event:FireServer("BodyColors", skinColor)
			event:FireServer("Change_Face", faceID)
			event:FireServer("RemovePackages", nil)
			
	-- [[ Rest of the function goes here xD ]] --
	clicksound:Play()
	canClick = false
	pop_up:TweenPosition(UDim2.new(1.75, 0, 0.5, 0), "InOut", "Quint", 1.25, false)
	wait(0.25)
	swooshsound:Play()
	wait(1.75)
	pop_up.Visible = false
	page1:WaitForChild("Texto").Text = 'Press → to continue.'
	do_main()
	end
end)

pop_up:FindFirstChild("DEF").MouseButton1Click:connect(function()
	if canClick then
	clicksound:Play()
	canClick = false
	pop_up:TweenPosition(UDim2.new(1.75, 0, 0.5, 0), "InOut", "Quint", 1.25, false)
	wait(0.25)
	swooshsound:Play()
	wait(1.75)
	pop_up.Visible = false
	do_main()
	end
end)

-- [[ STEP 1 BUTTONS ]] --

local vDb = true
local fDb = true

teamR.MouseButton1Click:connect(function()
	if vDb == true then
	if canClick == true then
		vDb = false
		if #teamList > 1 then
			clicksound:Play()
			teamIndex = teamIndex + 1
			if teamIndex > #teamList then
				teamIndex = 1
			end
			moveList(teamchoose, teamList[teamIndex])
			local suitname, suitID, suitPants = updateSuit(teamList[teamIndex], suitIndex)
			moveList(suitchoose, suitname)
			-- [[ Make sure to edit the list as well.. ]] --
			selectedSuit = suitchoose
			selectedSuitShirt = suitID
			selectedSuitPants = suitPants
			event:FireServer("ReplaceClothing", {selectedSuitShirt, selectedSuitPants})
		else
			noaccess:Play()
		end
		wait(1)
		vDb = true
	end
	end
end)

teamL.MouseButton1Click:connect(function()
	if vDb == true then
	if canClick == true then
		vDb = false
		if #teamList > 1 then
			clicksound:Play()
			teamIndex = teamIndex - 1
			if teamIndex < 1 then
				teamIndex = #teamList
			end
			moveList(teamchoose, teamList[teamIndex])
			local suitname, suitID, suitPants = updateSuit(teamList[teamIndex], suitIndex)
			moveList(suitchoose, suitname)
			-- [[ Make sure to edit the list as well.. ]] --
			selectedSuit = suitchoose
			selectedSuitShirt = suitID
			selectedSuitPants = suitPants
			event:FireServer("ReplaceClothing", {selectedSuitShirt, selectedSuitPants})
		else
			noaccess:Play()
		end
		wait(1)
		vDb = true
	end
	end
end)

suitR.MouseButton1Click:connect(function()
	if fDb == true then
	if canClick == true then
		fDb = false
		if #suitsettings[teamList[teamIndex]] > 1 then
			clicksound:Play()
			suitIndex = suitIndex + 1
			if suitIndex > #suitsettings[teamList[teamIndex]] then
				suitIndex = 1
			end
			local suitname, suitID, suitPants = updateSuit(teamList[teamIndex], suitIndex)
			moveList(suitchoose, suitname)
			-- [[ Make sure to edit the list as well.. ]] --
			selectedSuit = suitchoose
			selectedSuitShirt = suitID
			selectedSuitPants = suitPants
			event:FireServer("ReplaceClothing", {selectedSuitShirt, selectedSuitPants})
		else
			noaccess:Play()
		end
		wait(1)
		fDb = true
	end
	end
end)

suitL.MouseButton1Click:connect(function()
	if fDb == true then
	if canClick == true then
		fDb = false
		if #suitsettings[teamList[teamIndex]] > 1 then
			clicksound:Play()
			suitIndex = suitIndex - 1
			if suitIndex < 1 then
				suitIndex = #suitsettings[teamList[teamIndex]]
			end
			local suitname, suitID, suitPants = updateSuit(teamList[teamIndex], suitIndex)
			moveList(suitchoose, suitname)
			-- [[ Make sure to edit the list as well.. ]] --
			selectedSuit = suitchoose
			selectedSuitShirt = suitID
			selectedSuitPants = suitPants
			event:FireServer("ReplaceClothing", {selectedSuitShirt, selectedSuitPants})
		else
			noaccess:Play()
		end
		wait(1)
		fDb = true
	end
	end
end)

nextBtn1.MouseButton1Click:connect(function()
	if canClick == true then
	clicksound:Play()
	canClick = false
	local pos_frames = {}
		for i, v in pairs(page1:GetChildren()) do
			if v.Name == "<S" or v.Name == "<T" or v.Name == "BackBTN" or v.Name == "TextLabel" then
				table.insert(pos_frames, v.Position + UDim2.new(-1, 0, 0, 0))
			elseif v.Name == "S>" or v.Name == "T>" or v.Name == "NextBTN" then
				table.insert(pos_frames, v.Position + UDim2.new(1, 0, 0, 0))
			elseif v.Name == "TeamChoose" then
				table.insert(pos_frames, v.Position + UDim2.new(0, 0, -1, 0))
			else
				table.insert(pos_frames, v.Position + UDim2.new(0, 0, 1, 0))
			end
		end
		for i, frame in pairs(page1:GetChildren()) do
			if frame then
				frame:TweenPosition(pos_frames[i], "InOut", "Quint", 2)
				wait(.3)
			end
		end
		page1:TweenPosition(UDim2.new(0.025, 0, 0.23, 0) + UDim2.new(-1, 0, 0, 0), "InOut", "Quint", 2)
		wait(2)
		page1.Visible = false
		if ifL4 == true and custed == false then
			logo:TweenPosition(UDim2.new(-1, 0, 0, 0), "InOut", "Quint", 3)
			local getteam = nil
			if ifHR then
				print("Player HR")
				if string.sub(ifHR, 1, 2) == "O5" then
					local teamname = O5_teamlist[ifHR][1]
					print("Player O5")
					if teamname then
						getteam = game:GetService("Teams"):FindFirstChild(teamname)
						print("Getting team: " .. teamname)
					end
				elseif ifHR == "Administrator" then
					local teamname = O5_teamlist[ifHR][1]
					if teamname then
						getteam = game:GetService("Teams"):FindFirstChild(teamname)
						print("Getting team: " .. teamname)
					end
				elseif ifHR == "SpecialPeople" then
					local teamname = O5_teamlist[ifHR][1]
					if teamname then
						getteam = game:GetService("Teams"):FindFirstChild(teamname)
						print("Getting team: " .. teamname)
					end
				elseif ifHR == "Site Director" then
					local teamname = O5_teamlist[ifHR][1]
					if teamname then
						getteam = game:GetService("Teams"):FindFirstChild(teamname)
						print("Getting team: " .. teamname)
					end	
				end
			else
				local teamname = teamList[teamIndex]
				if teamname then
					getteam = game:GetService("Teams"):FindFirstChild(teamname)
					print("Getting team: " .. teamname)
				end
			end
			local suitname, suitID, suitPants = updateSuit(teamList[teamIndex], suitIndex)
			local char = player.Character
			event:FireServer("SetTeam", getteam)
			event:FireServer("SetValues", {suitID, suitPants, nil, nil, nil, false})
			event:FireServer("Freeze", false)
			event:FireServer("Teleport", workspace:WaitForChild("Spawns"):FindFirstChild(getteam.Name))
			event:FireServer("RemoveTP", nil)
			Handle_Ending()
			coroutine.resume(coroutine.create(function()
				while script.Parent.ScaryMusic.Volume > 0 do
					script.Parent.ScaryMusic.Volume = script.Parent.ScaryMusic.Volume - 0.01
					wait()
				end
				script.Parent.ScaryMusic:Stop()
			end))
		else
			print("Player might not be L4 or chose to cusotmize")
			do_mainP2()
		end
	end
end)
	
backBtn1.MouseButton1Click:connect(function()
	if canClick == true then
	clicksound:Play()
	canClick = false
	-- [[ MAIN WORK ]] --
	local pos_frames = {}
		for i, v in pairs(page1:GetChildren()) do
			if v.Name == "<S" or v.Name == "<T" or v.Name == "BackBTN" or v.Name == "TextLabel" then
				table.insert(pos_frames, v.Position + UDim2.new(-1, 0, 0, 0))
			elseif v.Name == "S>" or v.Name == "T>" or v.Name == "NextBTN" then
				table.insert(pos_frames, v.Position + UDim2.new(1, 0, 0, 0))
			elseif v.Name == "TeamChoose" then
				table.insert(pos_frames, v.Position + UDim2.new(0, 0, -1, 0))
			else
				table.insert(pos_frames, v.Position + UDim2.new(0, 0, 1, 0))
			end
		end
		for i, frame in pairs(page1:GetChildren()) do
			if frame then
				frame:TweenPosition(pos_frames[i], "InOut", "Quint", 2)
				wait(.3)
			end
		end
		page1:TweenPosition(UDim2.new(0.025, 0, 0.23, 0) + UDim2.new(-1, 0, 0, 0), "InOut", "Quint", 2)
		wait(2)
		page1.Visible = false
		-- [[ LOL ]] --
		detect_classD()
		local positions = {}
		for i, frame in pairs(choosefunc:GetChildren()) do
			if frame then
				frame.Visible = false
				frame.Position = frame.Position + UDim2.new(1, 0, 0, 0)
				table.insert(positions, frame.Position)
				wait(.001)
				frame.Position = frame.Position + UDim2.new(-1, 0, 0, 0)
			end
		end
		choosefunc.Position = choosefunc.Position + UDim2.new(-1, 0, 0, 0)
		choosefunc.Visible = true
		choosefunc:TweenPosition(UDim2.new(0.025, 0, 0.23, 0), "Out", "Quint", 3)
		wait(1.25)
		for i, frame in pairs(choosefunc:GetChildren()) do
			if frame then
				frame.Visible = true
				frame:TweenPosition(positions[i], "Out", "Quint", 2)
				wait(.3)
			end
		end
		wait(.6)
		canClick = true
	end
end)

-- [[ STEP 2 BUTTONS (still not done with coding?) ]] --

local ffDb = true
local hDb = true
local sDb = true

faceR.MouseButton1Click:connect(function()
	if ffDb == true then
	if canClick == true then
		ffDb = false
		if #facesettings > 1 then
			clicksound:Play()
			faceIndex = faceIndex + 1
			if faceIndex > #facesettings then
				faceIndex = 1
			end
			local facename, faceID = updateFace(faceIndex)
			moveList(facechoose, facename)
			-- [[ Make sure to edit the list as well.. ]] --
			selectedFace = faceID
			event:FireServer("Change_Face", faceID)
		else
			noaccess:Play()
		end
		wait(1)
		ffDb = true
	end
	end
end)

faceL.MouseButton1Click:connect(function()
	if ffDb == true then
	if canClick == true then
		ffDb = false
		if #facesettings > 1 then
			clicksound:Play()
			faceIndex = faceIndex - 1
			if faceIndex < 1 then
				faceIndex = #facesettings
			end
			local facename, faceID = updateFace(faceIndex)
			moveList(facechoose, facename)
			-- [[ Make sure to edit the list as well.. ]] --
			selectedFace = faceID
			event:FireServer("Change_Face", faceID)
		else
			noaccess:Play()
		end
		wait(1)
		ffDb = true
	end
	end
end)

hairR.MouseButton1Click:connect(function()
	if hDb == true then
	if canClick == true then
		hDb = false
		if #hairsettings > 1 then
			clicksound:Play()
			hairIndex = hairIndex + 1
			if hairIndex > #hairsettings then
				hairIndex = 1
			end
			local hairName, hairModel = updateHair(hairIndex)
			moveList(hairchoose, hairName)
			-- [[ Make sure to edit the list as well.. ]] --
			selectedHair = hairModel
			event:FireServer("Replace_hat", hairModel)
		else
			noaccess:Play()
		end
		wait(1)
		hDb = true
	end
	end
end)

hairL.MouseButton1Click:connect(function()
	if hDb == true then
	if canClick == true then
		hDb = false
		if #hairsettings > 1 then
			clicksound:Play()
			hairIndex = hairIndex - 1
			if hairIndex < 1 then
				hairIndex = #hairsettings
			end
			local hairName, hairModel = updateHair(hairIndex)
			moveList(hairchoose, hairName)
			-- [[ Make sure to edit the list as well.. ]] --
			selectedHair = hairModel
			event:FireServer("Replace_hat", hairModel)	
		else
			noaccess:Play()
		end
		wait(1)
		hDb = true
	end
	end
end)

skinR.MouseButton1Click:connect(function()
	if sDb == true then
	if canClick == true then
		sDb = false
		if #skinsettings > 1 then
			clicksound:Play()
			skinIndex = skinIndex + 1
			if skinIndex > #skinsettings then
				skinIndex = 1
			end
			local skin_name, skinColor = updateSkinColor(skinIndex)
			moveList(skinchoose, skin_name)
			-- [[ Make sure to edit the list as well.. ]] --
			selectedSkinColor = skinColor
			event:FireServer("BodyColors", selectedSkinColor)	
		else
			noaccess:Play()
		end
		wait(1)
		sDb = true
	end
	end
end)

skinL.MouseButton1Click:connect(function()
	if hDb == true then
	if canClick == true then
		hDb = false
		if #skinsettings > 1 then
			clicksound:Play()
			skinIndex = skinIndex - 1
			if skinIndex < 1 then
				skinIndex = #skinsettings
			end
			local skin_name, skinColor = updateSkinColor(skinIndex)
			moveList(skinchoose, skin_name)
			-- [[ Make sure to edit the list as well.. ]] --
			selectedSkinColor = skinColor
			event:FireServer("BodyColors", selectedSkinColor)		
		else
			noaccess:Play()
		end
		wait(1)
		hDb = true
	end
	end
end)

joinBtn2.MouseButton1Click:connect(function()
	if canClick == true then
		canClick = false
		clicksound:Play()
		-- [[ ]] --
		local pos_frames = {}
		for i, v in pairs(page2:GetChildren()) do
			
			if v.Name == "<S" or v.Name == "<H" or v.Name == "<F" or v.Name == "BackBTN" or v.Name == "TextLabel" then
				table.insert(pos_frames, v.Position + UDim2.new(-1, 0, 0, 0))
			elseif v.Name == "S>" or v.Name == "H>" or v.Name == "F>" or v.Name == "JoinBTN" then
				table.insert(pos_frames, v.Position + UDim2.new(1, 0, 0, 0))
			elseif v.Name == "HairChoose" then
				table.insert(pos_frames, v.Position + UDim2.new(0, 0, -1, 0))
			else
				table.insert(pos_frames, v.Position + UDim2.new(0, 0, 1, 0))
			end
		end
		wait(0.3)
		for i, frame in pairs(page2:GetChildren()) do
			if frame then
				frame:TweenPosition(pos_frames[i], "InOut", "Quint", 2)
				wait(.3)
			end
		end
		wait(.3)
		page2:TweenPosition(UDim2.new(0.025, 0, 0.23, 0) + UDim2.new(-1, 0, 0, 0), "InOut", "Quint", 2)
		wait(1.5)
		-- [[ ]] --
		logo:TweenPosition(UDim2.new(-1, 0, 0, 0), "InOut", "Quint", 3)
		-- [[ ]] --
		local getteam = nil
			if ifHR then
				print("Player HR")
				if string.sub(ifHR, 1, 2) == "O5" then
					local teamname = O5_teamlist[ifHR][1]
					print("Player O5")
					if teamname then
						getteam = game:GetService("Teams"):FindFirstChild(teamname)
						print("Getting team: " .. teamname)
					end
				elseif ifHR == "Administrator" then
					local teamname = O5_teamlist[ifHR][1]
					if teamname then
						getteam = game:GetService("Teams"):FindFirstChild(teamname)
						print("Getting team: " .. teamname)
					end
				elseif ifHR == "SpecialPeople" then
					local teamname = O5_teamlist[ifHR][1]
					if teamname then
						getteam = game:GetService("Teams"):FindFirstChild(teamname)
						print("Getting team: " .. teamname)
					end	
				elseif ifHR == "Site Director" then
					local teamname = O5_teamlist[ifHR][1]
					if teamname then
						getteam = game:GetService("Teams"):FindFirstChild(teamname)
						print("Getting team: " .. teamname)
					end	
				end
			else
				local teamname = teamList[teamIndex]
				if teamname then
					getteam = game:GetService("Teams"):FindFirstChild(teamname)
					print("Getting team: " .. teamname)
				end
			end
			local suitname, suitID, suitPants = updateSuit(teamList[teamIndex], suitIndex)
			local facename, faceID = updateFace(faceIndex)
			local skin_name, skinColor = updateSkinColor(skinIndex)
			local hairName, hairModel = updateHair(hairIndex)
			local char = player.Character
			event:FireServer("SetTeam", getteam)
			event:FireServer("SetValues", {suitID, suitPants, faceID, skinColor, hairModel, true})
			event:FireServer("Freeze", false)
			event:FireServer("Teleport", workspace:WaitForChild("Spawns"):FindFirstChild(getteam.Name))
			event:FireServer("RemoveTP", nil)
			Handle_Ending()
			coroutine.resume(coroutine.create(function()
				while script.Parent.ScaryMusic.Volume > 0 do
					script.Parent.ScaryMusic.Volume = script.Parent.ScaryMusic.Volume - 0.01
					wait()
				end
				script.Parent.ScaryMusic:Stop()
			end))
	end
end)

This is one of the local script that’s put into SCPF_MENUTOOLS script

Oh god, that’s very unorganized.

You are able to add a Vector3 value with a CFrame value, if you would like to learn more about CFrame then check the documentation.

local cdcs = game.Workspace:WaitForChild("CDC_SPAWNS")
local event = game.ReplicatedStorage:WaitForChild("Events")
local CDC = {
	{1, 0};
	{2, 0};
	{3, 0};
	{4, 0};
	{5, 0};
	{6, 0};
	{7, 0};
	{8, 0};
	{9, 0};
	{10, 0};
	{11, 0};
	{12, 0};
	{13, 0};
	{14, 0};
	{15, 0};
	{16, 0};
	{17, 0};
	{18, 0};
	{19, 0};
	{20, 0};
}

function checkavalible()
	for i = 1, #CDC do
		if CDC[i][2] < 2 then
			return CDC[i]
		end
	end
	-- [[ Else, return nil. ]] --
	return nil
end

function check_classD()
	
end

event.OnServerEvent:Connect(function(plr, reason)
	if reason == "PrepareCD" then
		local avalible = checkavalible()
		if avalible ~= nil then
			avalible[2] = avalible[2] + 1
			local cell_num = Instance.new("IntValue", plr)
			cell_num.Name = "CELL_NUM"
			cell_num.Value = avalible[1]
			local getspawn = cdcs:FindFirstChild("CD" .. avalible[1])
			print(plr.Name .. " has been placed in cell CD-" .. avalible[1] .. " which currently has " .. avalible[2] .. " people in it.")
		end
	elseif reason == "TPCD" then
		local cellname = plr:FindFirstChild("CELL_NUM")
		if cellname then
			local cd = cdcs:FindFirstChild("CD" .. cellname.Value)
			local torso = plr.Character:FindFirstChild("Torso")
			if torso then
				torso.CFrame = cd.CFrame + Vector3.new(0, 2, 0)
			end
		end
	end
end)

events script

A third argument shouldn’t be needed, as the player is the first argument on the server, the arguments sent from the client come after that. It might be that the parts don’t exist.