Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make this cutscene LocalScript run only once?

--run this line to figure out the cframe of the camera
--print("CFrame"..".new".."("..tostring(game.Workspace.CurrentCamera.CFrame)..")")

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
repeat wait() until char:FindFirstChild("Humanoid")
local Humanoid = char.Humanoid
local CSN = game.ReplicatedStorage.ANIMS.CSN_ENTRY
local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()
local CAM = game.Workspace.CurrentCamera
local CSN_INIT = script
local New_Spawn = game.Workspace.NEW_SPAWN

--START of TWEEN INFORMATION--
local TweenService = game:GetService("TweenService")

local tween = TweenService:Create(
	CAM,
	TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
	{
		CFrame = CFrame.new(-646.054138, 164.024734, -147.037491, 0.570161045, 0.425801575, -0.702573419, -1.49011594e-08, 0.855198145, 0.518301249, 0.821532965, -0.29551518, 0.487600654),
		Focus = CFrame.new(0, 0, 100)
	}
)

local tween2 = TweenService:Create(
	CAM,
	TweenInfo.new(0, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
	{
		CFrame = CFrame.new(-636.641602, 152.000275, -156.594635, 0.249401063, 0.531467378, 0.809531689, -0, 0.835947454, -0.548809588, -0.968400359, 0.136873692, 0.208486155),
		Focus = CFrame.new(0, 0, 100)
	}
)
local tween3 = TweenService:Create(
	CAM,
	TweenInfo.new(0, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
	{
		CFrame = CFrame.new(-279.35965, 60.4497643, -165.918503, -0.424983442, 0.155464441, 0.891751111, 7.45057971e-09, 0.985141456, -0.171745747, -0.905201137, -0.0729890913, -0.418668777),
		Focus = CFrame.new(0, 0, 100)
	}
)
local tween4 = TweenService:Create(
	CAM,
	TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
	{
		CFrame = CFrame.new(-279.337067, 60.929657, -165.929214, -0.425028265, -0.0617388301, 0.903072178, -0, 0.997671366, 0.068206124, -0.905180156, 0.0289895311, -0.42403847),
		Focus = CFrame.new(0, 0, 100)
	}
)
local tween5 = TweenService:Create(
	CAM,
	TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
	{
		CFrame = CFrame.new(-279.511627, 59.9801903, -165.903732, -0.450190842, 0.363028705, 0.815805376, 1.49011612e-08, 0.913625002, -0.406557918, -0.892932355, -0.183028638, -0.411305606),
		Focus = CFrame.new(0, 0, 100)
	}
)
local tween6 = TweenService:Create(
	CAM,
	TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
	{
		CFrame = CFrame.new(-279.35965, 60.4497643, -165.918503, -0.424983442, 0.155464441, 0.891751111, 7.45057971e-09, 0.985141456, -0.171745747, -0.905201137, -0.0729890913, -0.418668777),
		Focus = CFrame.new(0, 0, 100)
	}
)
--END of TWEEN INFORMATION--

--start the real cutscene

Controls:Disable()

local CutsceneAnim = Humanoid:LoadAnimation(CSN)
CutsceneAnim:Play()

CAM.CameraType = Enum.CameraType.Scriptable
tween2:Play()
wait(1.5)
tween:Play()
wait(2)
tween3:Play()
wait(2)
tween4:Play()
wait(0.1)
tween5:Play()
wait(0.1)
tween4:Play()
wait(0.1)
tween5:Play()
wait(0.2)
tween6:Play()

Controls:Enable()

CAM.CameraSubject = Humanoid
CAM.CameraType = Enum.CameraType.Custom
wait(0.2)
char.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(-260.583, 8.9, -166.083))

Here's a cutscene script I wrote (that could be beautified) that I need to run only once, when the player spawns. I tried disabling the script once it's done, but it breaks that way (Controls disable once the script is disabled.)

1 answer

✓ Accepted answer

put the script in the StarterPlayerScripts.. It will be cloned into Player.PlayerScripts for every player that joins and ran.. or if its a descendant of ScreenGui then make sure ScreenGui.ResetOnSpawn is false

2 comments

0

I tried the latter, and it worked! Thank you.

0

np

This discussion is preserved as it was. New answers, comments, and votes are closed.