So a few months ago, I asked for assistance on playing a cutscene from a ClickDetector. I’m thankful for the help that topic received, however, I have another issue with the cutscene.
Recently, I opened a public game with cutscenes, and they only showed up on my end. Below is a script for one of them, as an example. I am unsure how to apply this to all users in a server, so a solution to this would be helpful.
Thank you.
-- If you find any bugs, please contact me via Twitter. @_inventfvl or @cutscenify
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 canPlayCutscene = true
local didLastPointDoImmediateSwitch = false
local partOfCutsceneDuration = 0
local cutsceneDuration = 0
local cutsceneParts = workspace:WaitForChild(cutsceneName.Value)
local partToClickString = "GameStart"
local doesStartAtPlayer = script.DoesStartAndEndAtPlayer.Value
local timetaken = 0
local count = 0
local tweeningCompleted = false
local endTweenComplete = false
local cutscenePart
local Character = Players.LocalPlayer.Character
local lastCutscenePart
local childcount = 0
local fieldOfView = 70
local originalCFrame
local function 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
print("Switched")
local currentPointPart = tonumber(pointInstance.Name)
local nextPointPart = currentPointPart + 1
local nextPointPartInstance = pointInstance.Parent:FindFirstChild(tostring(nextPointPart))
camera.CFrame = nextPointPartInstance.CFrame
print("camera has switched")
didLastPointDoImmediateSwitch = true
end
end)
repeat
wait()
until tweeningCompleted
end
-- Methods --
local function 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
PlayPartOfCutscene(camera, cutsceneParts:WaitForChild(count), fieldOfView, true)
Character.Humanoid.WalkSpeed = 16
Character.Humanoid.JumpPower = 50
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
StarterGui:SetCore("ResetButtonCallback", true)
end
repeat
timetaken = timetaken + 0.01
wait()
until game:IsLoaded() == true
repeat
wait(0.1)
until workspace:FindFirstChild(partToClickString)
repeat
timetaken = timetaken + 0.01
wait()
until game:IsLoaded() == true
repeat
wait(0.1)
until #cutsceneParts:GetChildren() == script:WaitForChild("CutscenePartCount").Value
Character = Players.LocalPlayer.Character
local partToClick = workspace[partToClickString]
partToClick.ClickDetector.MouseClick:Connect(function(plr)
if not canPlayCutscene then
return
end
if plr ~= Players.LocalPlayer then
return
end
Character.Humanoid.WalkSpeed = 16
Character.Humanoid.JumpPower = 50
canPlayCutscene = false
PlayFullCutscene()
camera.CameraType = Enum.CameraType.Custom
camera.FieldOfView = 70
count = 0
wait(5)
canPlayCutscene = true
end)