As the title suggests, I have a script that runs perfectly the first time through, but the second time it seems to skip PART of the first part.
I’m making a round based game and after each round you can obviously play again. A server script is added to a model and that server script adds local scripts to both players. The server script then fires to both clients creating an intro sequence of sorts. After the systems runs its course, both local scripts are destroyed, and then the server script follows.
The intro script includes a black Frame instance being tweened to work as a transition screen,
the first time through, it transitions fine, from covering the screen, to allowing vision, covering again, and then allowing me to see the second player. Perfect.
The second time through, the initial tween to see the first player doesn’t happen but everything else does, such as animations and camera movements. I checked server and local side and the actual frame IS there but just remains at 0 BackgroundTransparency
I’ll try to share the code as best I can, I apologize if it’s rudimentary or even inefficient, I’m a solo developer who is self taught and I’ve been properly scripting for about a year now and haven’t had any sort of “professional help”.
Server Side:
local LocalBridge = game.ReplicatedStorage:WaitForChild("Scripts"):WaitForChild("LocalBridge")
local Active = script:WaitForChild("Active")
local Player1 = false
local Player2 = false
local Gamemode = false
local Room = false
Active.Changed:Connect(function()
Room = script.Parent
task.wait()
Player1 = Room:WaitForChild("Table"):WaitForChild("Data"):WaitForChild("Player1").Value
Player2 = Room:WaitForChild("Table"):WaitForChild("Data"):WaitForChild("Player2").Value
Gamemode = Room:WaitForChild("Table"):WaitForChild("Data"):WaitForChild("Gamemode").Value
task.wait()----------------------------------------------------------------------------------------------
local Char1 = game.Workspace:FindFirstChild(Player1)
local Char2 = game.Workspace:FindFirstChild(Player2)
task.wait()----------------------------------------------------------------------------------------------
local RoomNameVal = Instance.new("BoolValue")
Char1:WaitForChild("HumanoidRootPart").CFrame = Room:WaitForChild("Player1Intro"):WaitForChild("TeleportPlayer1").CFrame
Char2:WaitForChild("HumanoidRootPart").CFrame = Room:WaitForChild("Player2Intro"):WaitForChild("TeleportPlayer2").CFrame
task.wait()----------------------------------------------------------------------------------------------
RoomNameVal.Name = Room.Name
RoomNameVal.Value = true
task.wait()----------------------------------------------------------------------------------------------
local Val1 = RoomNameVal:Clone()
local Val2 = RoomNameVal:Clone()
task.wait()----------------------------------------------------------------------------------------------
Val1.Parent = Char1
Val2.Parent = Char2
task.wait()----------------------------------------------------------------------------------------------
local LocalScript1 = game.ReplicatedStorage:WaitForChild("Scripts"):WaitForChild("INTROClient"):Clone()
local LocalScript2 = game.ReplicatedStorage:WaitForChild("Scripts"):WaitForChild("INTROClient"):Clone()
local FirstPLR = game.Players:GetPlayerFromCharacter(Char1)
local SecondPLR = game.Players:GetPlayerFromCharacter(Char2)
local GameScriptServer = game.ReplicatedStorage:WaitForChild("Gamemodes"):WaitForChild("Server"):WaitForChild(Gamemode):Clone()
local GameScriptClient1 = game.ReplicatedStorage:WaitForChild("Gamemodes"):WaitForChild("Local"):WaitForChild(Gamemode):Clone()
local GameScriptClient2 = game.ReplicatedStorage:WaitForChild("Gamemodes"):WaitForChild("Local"):WaitForChild(Gamemode):Clone()
task.wait()----------------------------------------------------------------------------------------------
LocalScript1.Parent = Char1
LocalScript2.Parent = Char2
task.wait()----------------------------------------------------------------------------------------------
LocalScript1.Enabled = true
LocalScript2.Enabled = true
task.wait()----------------------------------------------------------------------------------------------
LocalBridge:FireClient(FirstPLR, "MoveToIntroCam1", Room)
LocalBridge:FireClient(SecondPLR, "MoveToIntroCam1", Room)
task.wait(1)----------------------------------------------------------------------------------------------
LocalBridge:FireClient(FirstPLR, "PlayIntro", Room)
task.wait(5.5)----------------------------------------------------------------------------------------------
LocalBridge:FireClient(FirstPLR, "MoveToIntroCam2", Room)
LocalBridge:FireClient(SecondPLR, "MoveToIntroCam2", Room)
task.wait(1.7)----------------------------------------------------------------------------------------------
LocalBridge:FireClient(SecondPLR, "PlayIntro", Room)
task.wait(5.5)----------------------------------------------------------------------------------------------
LocalBridge:FireClient(FirstPLR, "SetTheScene", Room)
LocalBridge:FireClient(SecondPLR, "SetTheScene", Room)
task.wait(2)
Char1:WaitForChild("HumanoidRootPart").CFrame = Room:WaitForChild("Table"):WaitForChild("Chair1"):WaitForChild("TeleportChair1").CFrame
Char2:WaitForChild("HumanoidRootPart").CFrame = Room:WaitForChild("Table"):WaitForChild("Chair2"):WaitForChild("TeleportChair2").CFrame
task.wait(1)
GameScriptClient1.Parent = Char1
GameScriptClient2.Parent = Char2
GameScriptServer.Parent = Room
print("Game is ready to start!")
task.wait()
GameScriptServer.Enabled = true
task.wait()
GameScriptServer:WaitForChild("Active").Value = true
GameScriptClient1.Enabled = true
GameScriptClient2.Enabled = true
task.wait(3)
LocalScript1:Destroy()
LocalScript2:Destroy()
script:Destroy()
end)
Local Side:
local Player = game.Players.LocalPlayer
local TweenService = game:GetService("TweenService")
local LocalBridge = game.ReplicatedStorage:WaitForChild("Scripts"):WaitForChild("LocalBridge")
local Camera = game.Workspace:WaitForChild("Camera")
LocalBridge.OnClientEvent:Connect(function(Key, Room)
if Key == "MoveToIntroCam1" then
local Cam1 = Room:WaitForChild("Player1Intro"):WaitForChild("Camera1")
local TransitionFrame = Player.PlayerGui:WaitForChild("TransitionFrame")
task.wait()----------------------------------------------------------------------------------------------
for i,anim in ipairs (Player.Character:WaitForChild("Humanoid"):WaitForChild("Animator"):GetPlayingAnimationTracks()) do
anim:Stop()
end
task.wait()----------------------------------------------------------------------------------------------
Camera.CameraType = Enum.CameraType.Scriptable
task.wait()
Camera.CFrame = Cam1.CFrame
task.wait(1)----------------------------------------------------------------------------------------------
TweenService:Create(TransitionFrame.BlackFrame, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {BackgroundTransparency = 1}):Play()
task.wait(1)
return
end
end)
LocalBridge.OnClientEvent:Connect(function(Key, Room)
if Key == "MoveToIntroCam2" then
local Cam1 = Room:WaitForChild("Player2Intro"):WaitForChild("Camera2")
local TransitionFrame = Player.PlayerGui:WaitForChild("TransitionFrame")
TweenService:Create(TransitionFrame.BlackFrame, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {BackgroundTransparency = 0}):Play()
task.wait(1)----------------------------------------------------------------------------------------------
for i,anim in ipairs (Player.Character:WaitForChild("Humanoid"):WaitForChild("Animator"):GetPlayingAnimationTracks()) do
anim:Stop()
end
task.wait()----------------------------------------------------------------------------------------------
Camera.CameraType = Enum.CameraType.Scriptable
task.wait()
Camera.CFrame = Cam1.CFrame
task.wait(1)----------------------------------------------------------------------------------------------
TweenService:Create(TransitionFrame.BlackFrame, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {BackgroundTransparency = 1}):Play()
task.wait(1)
return
end
end)
LocalBridge.OnClientEvent:Connect(function(Key, Room)
if Key == "PlayIntro" then
local Humanoid = Player.Character:WaitForChild("Humanoid")
local IntroAnim = Player:WaitForChild("DataFolder"):WaitForChild("Equipped"):WaitForChild("IntroAnimation").Value
task.wait()
local AnimID = game.ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Intros"):WaitForChild(IntroAnim)
task.wait()----------------------------------------------------------------------------------------------
local AnimTrack = Humanoid:WaitForChild("Animator"):LoadAnimation(AnimID)
task.wait()----------------------------------------------------------------------------------------------
AnimTrack:Play()
while AnimTrack.TimePosition < 5 do
task.wait()
end
AnimTrack:AdjustSpeed(0)
end
end)
LocalBridge.OnClientEvent:Connect(function(Key, Room)
if Key == "SetTheScene" then
local Humanoid = Player.Character:WaitForChild("Humanoid")
local TransitionFrame = Player.PlayerGui:FindFirstChild("TransitionFrame")
local SeatedAnim = Player:WaitForChild("DataFolder"):WaitForChild("Equipped"):WaitForChild("SittingAnimations").Value
task.wait()
local AnimID = game.ReplicatedStorage:WaitForChild("Animations"):WaitForChild("AnimPacks"):WaitForChild(SeatedAnim):WaitForChild("Sitting")
TweenService:Create(TransitionFrame.BlackFrame, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {BackgroundTransparency = 0}):Play()
task.wait()
local AnimTrack = Humanoid:WaitForChild("Animator"):LoadAnimation(AnimID)
task.wait(2)
for i,anim in ipairs (Player.Character:WaitForChild("Humanoid"):WaitForChild("Animator"):GetPlayingAnimationTracks()) do
anim:Stop()
end
task.wait()
AnimTrack:Play()
task.wait(2)
Camera.CameraType = Enum.CameraType.Follow
TweenService:Create(TransitionFrame.BlackFrame, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {BackgroundTransparency = 1}):Play()
task.wait(1)
return
end
end)
If anybody has any sort of idea why it’s happening or has any advice in general please let me know. Any help means the world to me and goes quite a long way since I get most of my knowledge from Forums and then Documentation.
Thank you for your time and you patience, stay safe.
ACherryPy-
(Sidenote: Would there be a way to create unique remote events for each script? Lets say max server size if 50 people and there are 50 people stressing out that RemoteEvent, would it buffer or would roblox be able to manage that? Again I have no idea so that’s why I ask. If you guys have any advice or help whatsoever, it means the world to me.)