I’m writing a ModuleScript located in ServerScriptService to play an intro cutscene when I need it to. But it keeps erroring the following whenever I add the PlayerGui statement
ServerScriptService.IntroScript:17: attempt to index nil with 'WaitForChild' - Server - IntroScript:17
I’m trying to make it so the logo pops up with the camera. Here is the code.
--//Intro Script//
--[Services]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local TweenService = game:GetService("TweenService")
--[Variables]
local PluginsFolder = ServerScriptService:WaitForChild("Plugins")
local AssetsFolder = ReplicatedStorage:WaitForChild("Assets")
local Camera = workspace.CurrentCamera
--[Player]
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
--[Required Modules]
local Utilities = require(PluginsFolder:WaitForChild("Utilities"))
local Images = require(AssetsFolder:WaitForChild("Images"))
local Audio = require(AssetsFolder:WaitForChild("Audio"))
--
local CreateObject = Utilities.CreateObject()
local IntroScript = {}
function IntroScript:PlayIntro()
local Chunk = workspace:WaitForChild("titlescreen")
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Chunk:WaitForChild("Cutscene"):WaitForChild("cam1").CFrame
Utilities.PlaySound(Audio.MainTheme)
TweenService:Create(
Camera,
TweenInfo.new(4.0, Enum.EasingStyle.Back, Enum.EasingDirection.Out),
{CFrame = Chunk:WaitForChild("Cutscene"):WaitForChild("cam2").CFrame}):Play()
task.wait(4.0)
local Gui = Instance.new("ScreenGui")
Gui.Parent = PlayerGui
local Logo = CreateObject "ImageLabel" {
BackgroundTransparency = 1.0,
Image = ("rbxassetid://"..Images.Logo),
ImageTransparency = 1.0,
Position = UDim2.new(0.105, 0 ,0.082, 0),
Size = UDim2.new(0.79, 0, 0.835, 0),
AnchorPoint = Vector2.new(0.5, 0.5),
Parent = Gui}
TweenService:Create(Logo,
TweenInfo.new(1.0),
{ImageTransparency = 0.0}):Play()
TweenService:Create(
Camera,
TweenInfo.new(1.0, Enum.EasingStyle.Quart, Enum.EasingDirection.Out),
{CFrame = Chunk:WaitForChild("Camera").CFrame}):Play()
end
return IntroScript
The error happens around here:
--[Player]
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
Could you be calling the module script inside a server script? You are making a variable named “Player” by “LocalPlayer” but LocalPlayer is only accessible on Local Scripts.
The script calling and firing the function is a server script. That is probably the issue, is there any workaround I can take to make this work still with a server script?
I’m not trying to play the intro first thing when the player joins in, my end goal is to have it play after everything is loaded. Is there any other workaround?
In the server script used to signal the intro playing after everything is loaded in this is the function I use.
--[Playing the Intro]
local Loaded = Instance.new("RemoteEvent")
Loaded.Parent = ReplicatedStorage
Loaded.Name = "Loaded"
Loaded.OnServerEvent:Wait()
do
local IntroScript = require(ServerScriptService:WaitForChild("IntroScript"))
IntroScript:PlayIntro()
Loaded:Remove()
end
local Player
local Loaded = Instance.new("RemoteEvent")
Loaded.Parent = ReplicatedStorage
Loaded.Name = "Loaded"
Loaded.OnServerEvent:Connect(function(PlayerReal)
Player = PlayerReal
end)
Loaded.OnServerEvent:Wait()
do
local IntroScript = require(ServerScriptService:WaitForChild("IntroScript"))
IntroScript:PlayIntro(Player)
Loaded:Remove()
end
Then just the function with the player argument in the function I posted earlier.