local PlayButton = script.Parent.PLAY
local QuitButton = script.Parent.QUIT
local SettingsButton = script.Parent.SETTINGS
PlayButton.MouseButton1Click:Connect(function()
--Camera.CameraType = Enum.CameraType.Custom
PlayButton:Destroy()
Logo:Destroy()
Credit:Destroy()
QuitButton:Destroy()
SettingsButton:Destroy()
print ("Starting Game!")
local module = require(workspace.CutsceneExecutionModule)
module:PlayFullCutscene()
end)
The Actual Module:
local module = {}
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local camera = workspace.CurrentCamera
local cutsceneName = script.CutsceneName
if not cutsceneName then
warn("CutsceneName does not exist, cutscene cannot run.")
end
local easingStyle
local easingDirection
local didLastPointDoImmediateSwitch = false
local cutsceneParts = workspace:WaitForChild(cutsceneName.Value)
local doesStartAtPlayer = script.DoesStartAndEndAtPlayer.Value
local repeatValue
local tweeningCompleted = false
local endTweenComplete = false
local lastCutscenePart
local cutscenePart
local Character
local count = 0
local timetaken = 0
local childcount = 0
local fieldOfView = 70
local originalCFrame
function module:IsModuleLoaded()
--[[
When executing your cutscene from this ModuleScript, use this API so your code can work properly.
Otherwise, your code will error since the model for the cutscene parts will not have loaded in yet.
Code For Waiting:
local module = require(workspace.CutsceneExecutionModule)
repeat
wait(0.01)
until module:IsModuleLoaded() == true
]]
if #cutsceneParts:GetChildren() == script.CutscenePartCount.Value then
return true
else
return false
end
end
repeat
timetaken = timetaken + 0.01
wait()
until game:IsLoaded() == true
repeat
wait(0.1)
until #cutsceneParts:GetChildren() == script.CutscenePartCount.Value
Character = Players.LocalPlayer.Character
function module:PlayPartOfCutscene(cameraInstance, pointInstance, fieldOfView, isFirst)
camera.CameraType = Enum.CameraType.Scriptable
lastCutscenePart = #pointInstance.Parent:GetChildren()
local tweeningTable = {
CFrame = pointInstance.CFrame
}
if pointInstance.EasingDirection.Value == 1 then
easingDirection = Enum.EasingDirection.In
elseif pointInstance.EasingDirection.Value == 2 then
easingDirection = Enum.EasingDirection.Out
elseif pointInstance.EasingDirection.Value == 3 then
easingDirection = Enum.EasingDirection.InOut
end
if pointInstance.EasingStyle.Value == 1 then
easingStyle = Enum.EasingStyle.Linear
elseif pointInstance.EasingStyle.Value == 2 then
easingStyle = Enum.EasingStyle.Quad
elseif pointInstance.EasingStyle.Value == 3 then
easingStyle = Enum.EasingStyle.Quart
elseif pointInstance.EasingStyle.Value == 4 then
easingStyle = Enum.EasingStyle.Quint
elseif pointInstance.EasingStyle.Value == 5 then
easingStyle = Enum.EasingStyle.Sine
elseif pointInstance.EasingStyle.Value == 6 then
easingStyle = Enum.EasingStyle.Back
elseif pointInstance.EasingStyle.Value == 7 then
easingStyle = Enum.EasingStyle.Bounce
elseif pointInstance.EasingStyle.Value == 8 then
easingStyle = Enum.EasingStyle.Circular
elseif pointInstance.EasingStyle.Value == 9 then
easingStyle = Enum.EasingStyle.Cubic
elseif pointInstance.EasingStyle.Value == 10 then
easingStyle = Enum.EasingStyle.Elastic
elseif pointInstance.EasingStyle.Value == 11 then
easingStyle = Enum.EasingStyle.Exponential
end
local tweenInfoCamMovement = TweenInfo.new(tonumber(pointInstance:WaitForChild("TransitionTime").Value), easingStyle, easingDirection, 0, false, 0)
if isFirst then
local tweenInfoCamMovement = TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
end
local tween = TweenService:Create(cameraInstance, tweenInfoCamMovement, tweeningTable)
if not didLastPointDoImmediateSwitch then
tween:Play()
end
local FOVTweeningTable = {
FieldOfView = fieldOfView
}
local FormattedTweenInfo = TweenInfo.new(tonumber(pointInstance:WaitForChild("TransitionTime").Value), easingStyle, easingDirection, 0, false, 0)
local FOVTween = TweenService:Create(camera, FormattedTweenInfo, FOVTweeningTable)
if not didLastPointDoImmediateSwitch then
FOVTween:Play()
end
tweeningCompleted = false
if didLastPointDoImmediateSwitch then
tweeningCompleted = true
end
didLastPointDoImmediateSwitch = false
tween.Completed:Connect(function()
tweeningCompleted = true
if pointInstance.Name == tostring(lastCutscenePart) or pointInstance.ImmediateSwitch.Value == false then
print("")
else
local currentPointPart = tonumber(pointInstance.Name)
local nextPointPart = currentPointPart + 1
local nextPointPartInstance = pointInstance.Parent:FindFirstChild(tostring(nextPointPart))
camera.CFrame = nextPointPartInstance.CFrame
didLastPointDoImmediateSwitch = true
end
return
end)
repeat
camera.CFrame = camera.CFrame
wait(0.001)
until tweeningCompleted
end
-- Methods --
function module:PlayFullCutscene()
originalCFrame = camera.CFrame
StarterGui:SetCore("ResetButtonCallback", false)
local children = cutsceneParts:GetChildren()
for i, pointPartInstance in ipairs(children) do
cutscenePart = pointPartInstance
count = count + 1
if count == 1 and not doesStartAtPlayer then
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = cutsceneParts:WaitForChild("1").CFrame
else
fieldOfView = cutsceneParts:WaitForChild(count):WaitForChild("CameraFOV").Value
module:PlayPartOfCutscene(camera, cutsceneParts:WaitForChild(count), fieldOfView, true)
Character.Humanoid.WalkSpeed = 0
Character.Humanoid.JumpPower = 0
end
end
if doesStartAtPlayer then
local tweeningTable = {
CFrame = originalCFrame
}
local tweenInfoCamMovement = TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
local tween = TweenService:Create(camera, tweenInfoCamMovement, tweeningTable)
tween:Play()
local FOVTweeningTable = {
FieldOfView = 70
}
local tweenInfoFov = TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
local tweenFov = TweenService:Create(camera, tweenInfoFov, FOVTweeningTable)
tweenFov:Play()
tween.Completed:Connect(function()
endTweenComplete = true
end)
repeat
camera.CFrame = camera.CFrame
wait(0.001)
until endTweenComplete
end
camera.FieldOfView = 70
camera.CameraType = Enum.CameraType.Custom
Character.Humanoid.WalkSpeed = 16
Character.Humanoid.JumpPower = 50
count = 0
StarterGui:SetCore("ResetButtonCallback", true)
end
return module
you must set value to false here:
and you can simplify your script like this:
local Module = workspace:WaitForChild("CutsceneExecutionModule")
local Gui = script.Parent:WaitForChild("StartScreen")
local PlayButton = Gui:WaitForChild("PLAY")
PlayButton.MouseButton1Click:Connect(function()
print ("Starting Game!")
Gui:Destroy()
local module1 = require(Module)
module1:PlayFullCutscene()
end)