Hello! I’m new to the Developer Forum, so this is my first topic.
I know the basics of scripting, but I do not understand complex ones.
- What do you want to achieve?
- So, I tried using ChatGPT for roblox scripting, and I was asking it to make a cinematic intro whenever the local player joins into the game.
- The main aspect did work, the CurrentCamera teleported to certain areas, showcasing the map whilst the menu start screen was visible, and moving from one position to the other. But I wanna make it so whenever you press the play button, the CurrentCamera should return to the default player following camera. Therefore the player won’t be stuck on the menu, nor the CurrentCamera.
-
What is the issue?
However, ChatGPT struggled to make the Play Button stop the whole cinematic camera movement loop, and return it to the local player’s camera. I tried a lot of attempts but none worked, since I have no strong scripting knowledge.
This is how things look in the explorer (just incase):
-
What solutions have you tried so far?
Not much, I couldn’t find any. And ChatGPT struggles to do large complex ones so it kept messing it up and making it worse. The solution seems very simple, I just don’t know what it is.
Here’s the LocalScript (IntroCinematic) inside of StarterPlayerScripts:
local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local starterGui = game:GetService("StarterGui")
local playButton = game.StarterGui.StartScreen.RandomFrame.Play
local debounce = false
-- Define the list of camera positions, orientations, and speeds for the cinematic
local cameraInfo = {
{position = Vector3.new(-111.086, 87.413, -118.91), lookAt = Vector3.new(-45.165, 87.413, 364.618), speed = 100},
{position = Vector3.new(-585.882, 120.878, 290.307), lookAt = Vector3.new(-776.856, 120.787, -503.379), speed = 150},
{position = Vector3.new(158.075, 120.546, -528.272), lookAt = Vector3.new(611.28, 120.822, -11.763), speed = 300},
{position = Vector3.new(488.812, 120.772, 620.441), lookAt = Vector3.new(502.664, 120.772, 579.402), speed = 20},
}
local currentCameraIndex = 1
local isCinematicActive = false
local function startCinematicLoop()
if debounce or isCinematicActive then return end
debounce = true
-- Disable default player controls
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.PlatformStand = true
isCinematicActive = true
while true do
-- Get the current camera info
local currentPosition = cameraInfo[currentCameraIndex].position
local currentLookAt = cameraInfo[currentCameraIndex].lookAt
local speed = cameraInfo[currentCameraIndex].speed
-- Set initial camera properties
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(currentPosition, currentLookAt)
-- Calculate the direction and distance to move
local direction = (currentLookAt - currentPosition).unit
local distance = (currentLookAt - currentPosition).magnitude
-- Calculate the time needed to reach the next position based on speed
local timeToReach = distance / speed
-- Smoothly interpolate camera position and orientation over time
local startTime = tick()
local currentTime = 0
while currentTime < timeToReach do
local alpha = currentTime / timeToReach
local newPosition = currentPosition + direction * speed * alpha
camera.CFrame = CFrame.new(newPosition, currentLookAt)
currentTime = tick() - startTime
wait()
end
-- Move to the next camera position
currentCameraIndex = currentCameraIndex % #cameraInfo + 1
isCinematicActive = false
end
end
local function endCinematicLoop()
debounce = false
-- Enable default player controls
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.PlatformStand = false
-- Show GUI for ending cinematic
starterGui:SetCore("GuiEnabled", {
PlayerList = true,
Backpack = true,
Chat = true,
All = true,
})
end
playButton.MouseButton1Click:Connect(function()
endCinematicLoop()
end)
player.CharacterAdded:Connect(function()
startCinematicLoop()
end)
I would have to get the play button like this:
playButton = game.StarterGui.StartScreen.RandomFrame.Play
Any help would be much appreciated! I’m slowly learning, so explaining things simply would be helpful. If possible, make it clear what steps I need to do to fix this issue in certain parts of the LocalCcript.