Why is this Module Script not working?

I’m a bit new to the scripting world and am quite curious why this Module won’t run. It is being called from a normal script via StarterGui and attempting to execute a Module in ServerScriptService. The goal is to have a cutscene play when the GUI ‘‘play’’ button is hit. I’d appreciate some help, preferably dumbed down for a beginner. Thank you and all the best.

Code:

local PlayButton = script.Parent.PLAY 
PlayButton.MouseButton1Click:Connect(function()
	--Camera.CameraType = Enum.CameraType.Custom
	PlayButton:Destroy()
	print ("Starting Game!")
	local module = require(workspace.CutsceneExecutionModule)
	repeat
		wait(0.01)
	until module:IsModuleLoaded() == true
	module:IsModuleLoaded()

Use local script instead of normal script. You write that the module script is in “ServerScriptService”, but in the script it is written in “workspace”. And show me your modul script.

This is the Module. It’s from a cutscene creation plugin that I use consistently.

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

try this:

local PlayButton = script.Parent.PLAY 
PlayButton.MouseButton1Click:Connect(function()
	--Camera.CameraType = Enum.CameraType.Custom
	PlayButton:Destroy()
	print ("Starting Game!")
	local module = require(workspace.CutsceneExecutionModule)
	repeat
		wait(0.01)
	until module:PlayFullCutscene() == true
	module:PlayFullCutscene()
end)
local Frame = script.Parent
local Button = Frame:WaitForChild("PLAY")
local Module = workspace:WaitForChild("CutsceneExecutionModule")

Button.MouseButton1Click:Connect(function()
	local CSModule = require(Module)
	repeat
		task.wait()
	until CSModule:IsModuleLoaded() == true
	CSModule:IsModuleLoaded()
	Button:Destroy()
end)

Because you were attempting to destroy the button before loading the module, you should move the destroying of the button to the end of the callback function connected to the button’s click event, also you should use task.wait() instead of wait() and there is no need to pass “0.01” as an argument as the minimum wait duration is 1 frame which is around (0.015) seconds. It’s also worth adding waits to allows for instances to load (replicate to the client) before attempting to reference them from within the script.