I use a button to move through scenarios, but it didn’t work when I clicked the button, I just stay in esc1
, and I needed to go through esc2, esc3, and the others.
local CurrentCamera = workspace.CurrentCamera
local MenuCameraPart = workspace:WaitForChild("MenuCamera") -- This is your menu camera
local PlayBTN = script.Parent.BG.Play_btn -- Your play button
local escenario = workspace.Model.escenario -- Referencia al modelo ESCENARIO dentro de workspace.Model
local Players = game:GetService("Players")
local transport = workspace.Model:WaitForChild("teleport")
local botones = game.menu.Flechas.Frame -- Los botones que queremos hacer visibles
-- Variables de control de cámara y escenarios
local escParts = {} -- Tabla para almacenar las partes de los escenarios (cámaras)
local currentEscIndex = 1 -- Índice actual de la cámara
local numEscenarios = 5 -- Sabemos que hay 5 escenarios
-- Asignar manualmente las partes de los escenarios a la tabla escParts
escParts[1] = escenario:WaitForChild("esc1")
escParts[2] = escenario:WaitForChild("esc2")
escParts[3] = escenario:WaitForChild("esc3")
escParts[4] = escenario:WaitForChild("esc4")
escParts[5] = escenario:WaitForChild("esc5")
-- Set the camera to MenuCamera at the start
CurrentCamera.CameraType = Enum.CameraType.Scriptable
CurrentCamera.CFrame = MenuCameraPart.CFrame
-- Hacer invisible los botones de navegación al inicio
-- Función para cambiar la cámara al escenario actual
local function setEscenarioCamera(index)
if escParts[index] then
CurrentCamera.CameraType = Enum.CameraType.Scriptable
CurrentCamera.CFrame = escParts[index].CFrame
end
end
-- Función para congelar al jugador
local function FreezePlayer(player)
local humanoid = player.Character:FindFirstChild("Humanoid")
local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
if humanoid and humanoidRootPart then
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position, humanoidRootPart.Position + Vector3.new(0, 0, 1))
end
end
-- Función cuando se hace clic en el botón "Play"
local function Play()
CurrentCamera.CameraType = Enum.CameraType.Scriptable
setEscenarioCamera(currentEscIndex) -- Muestra la primera cámara del escenario
local player = game.Players.LocalPlayer
if player and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
player.Character.HumanoidRootPart.CFrame = transport.CFrame
FreezePlayer(player)
end
print( "line 58")
-- Mostrar los botones de navegación
script.Parent:Destroy() -- Destruir el GUI de Play después de hacer clic
end
-- Conectar el botón de "Play"
PlayBTN.MouseButton1Click:Connect(Play)
-- Funciones para navegar entre las cámaras (izquierda y derecha)
local function goLeft()
currentEscIndex = (currentEscIndex - 1) < 1 and numEscenarios or (currentEscIndex - 1)
setEscenarioCamera(currentEscIndex)
end
local function goRight()
currentEscIndex = (currentEscIndex + 1) > numEscenarios and 1 or (currentEscIndex + 1)
setEscenarioCamera(currentEscIndex)
end
-- Conectar los botones de flecha para navegar entre las cámaras
botones.abajo.MouseButton1Click:Connect(goLeft)
botones.arriba.MouseButton1Click:Connect(goRight)
print("last one")
I tried to useChatGPT, but nothing.
New contributor
AL-proyectos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.