Server Script passing over a function for whatever reason

As the title suggests, I have a server script that is trying to use a RemoteEvent to fire to a client. I’m making a round based game and the script works flawlessly the first time through, but when I respawn and try again, it suddenly gives me problems.

I’m not sure why because nothing about the player changes. The script SHOULD work fine (famous last words), I’ve tried using print functions to see what the problem is and it literally just skips over a function.

Here’s my entire Server Side:

local LocalBridge = game.ReplicatedStorage:WaitForChild("Scripts"):WaitForChild("LocalBridge")
local Active = script:WaitForChild("Active")
local Players = game:GetService("Players")
local Player1 = false
local Player2 = false
local Gamemode = false
local Room = false
local timeout = 5
local start = tick()

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 LocalScript1 = game.ReplicatedStorage:WaitForChild("Scripts"):WaitForChild("INTROClient"):Clone()
	local LocalScript2 = game.ReplicatedStorage:WaitForChild("Scripts"):WaitForChild("INTROClient"):Clone()
	
	local FirstPLR = Players:FindFirstChild(Player1)
	local SecondPLR = Players:FindFirstChild(Player2)
	
	if not FirstPLR or not SecondPLR then
		warn("Players missing, aborting intro")
		return
	end
	
	task.wait()
	
	local Char1 = FirstPLR.Character or FirstPLR.CharacterAdded:Wait()
	local Char2 = SecondPLR.Character or SecondPLR.CharacterAdded:Wait()
	
	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(0.1)----------------------------------------------------------------------------------------------
	
	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()----------------------------------------------------------------------------------------------
	
	LocalScript1.Parent = Char1
	LocalScript2.Parent = Char2
	
	task.wait(0.1)----------------------------------------------------------------------------------------------
	
	LocalScript1.Enabled = true
	LocalScript2.Enabled = true
	
	task.wait(0.1)
	
	while not (FirstPLR and SecondPLR and Room) do
		if tick() - start > timeout then
			warn("Intro camera failed: missing player or room")
			return
		end
		task.wait()
	end

	LocalBridge:FireClient(FirstPLR, "MoveToIntroCam1", Room)
	LocalBridge:FireClient(SecondPLR, "MoveToIntroCam1", Room)
	
	task.wait(2.1)----------------------------------------------------------------------------------------------
	
	LocalBridge:FireClient(FirstPLR, "PlayIntro", Room)
	
	task.wait(5.5)----------------------------------------------------------------------------------------------
	
	LocalBridge:FireClient(FirstPLR, "MoveToIntroCam2", Room)
	LocalBridge:FireClient(SecondPLR, "MoveToIntroCam2", Room)
	
	task.wait(1.8)----------------------------------------------------------------------------------------------
	
	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)

And here’s my entire Local Side:

local Player = game.Players.LocalPlayer
local TweenService = game:GetService("TweenService")
local LocalBridge = game.ReplicatedStorage:WaitForChild("Scripts"):WaitForChild("LocalBridge")
local Camera = game.Workspace.CurrentCamera
local MainAudios = game.Workspace:WaitForChild("PreloadZone")
local Debounce = false

LocalBridge.OnClientEvent:Connect(function(Key, Room, ConfirmValueName)
	if Key == "MoveToIntroCam1" and Debounce == false then
		
		local Cam1 = Room:WaitForChild("Player1Intro"):WaitForChild("Camera1")
		local TransitionFrame = Player.PlayerGui:WaitForChild("TransitionFrame")
		local AudioIn = MainAudios:WaitForChild("IntroAppear"):Clone()
		print("Values made!")
		
		task.wait()----------------------------------------------------------------------------------------------
		
		AudioIn.Parent = Player.PlayerGui
		local BlackFrame = TransitionFrame:WaitForChild("BlackFrame")
		print("Black Frame found and valued!")
		
		for i,anim in ipairs (Player.Character:WaitForChild("Humanoid"):WaitForChild("Animator"):GetPlayingAnimationTracks()) do
			anim:Stop()
		end
		print("Animations stopped!")
		
		task.wait()----------------------------------------------------------------------------------------------
		
		BlackFrame.BackgroundTransparency = 0
		print("Black frame transaprency set to 0!")
		
		task.wait()----------------------------------------------------------------------------------------------
		
		Camera.CameraType = Enum.CameraType.Scriptable
		task.wait()
		Camera.CFrame = Cam1.CFrame
		print("Camera moved to Cam1!")
		
		task.wait(2.5)----------------------------------------------------------------------------------------------
		
		print("Tweening Black Frame now!")
		AudioIn.Playing = true
		TweenService:Create(BlackFrame, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {BackgroundTransparency = 1}):Play()
		
		task.wait(6)
		
		AudioIn:Destroy()
		
	else if Key == "MoveToIntroCam2" then
			
			local Cam1 = Room:WaitForChild("Player2Intro"):WaitForChild("Camera2")
			local TransitionFrame = Player.PlayerGui:WaitForChild("TransitionFrame")
			local AudioIn = MainAudios:WaitForChild("IntroAppear"):Clone()
			local AudioOut = MainAudios:WaitForChild("IntroFade"):Clone()
			
			task.wait()
			
			AudioOut.Parent = Player.PlayerGui
			
			task.wait()
			
			AudioOut.Playing = true
			TweenService:Create(TransitionFrame.BlackFrame, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {BackgroundTransparency = 0}):Play()

			task.wait(1)----------------------------------------------------------------------------------------------
			
			AudioIn.Parent = Player.PlayerGui
			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)----------------------------------------------------------------------------------------------

			local Tween = TweenService:Create(TransitionFrame.BlackFrame, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {BackgroundTransparency = 1})

			task.wait()

			Tween:Play()
			
			AudioIn.Playing = true
			
			task.wait(6)
			
			AudioIn:Destroy()
			AudioOut:Destroy()
			
		else 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)
				
			else 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
					local AudioOut = MainAudios:WaitForChild("IntroFade"):Clone()
					
					task.wait()
					
					AudioOut.Parent = Player.PlayerGui

					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()
					AudioOut.Playing = true

					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
					local Tween = TweenService:Create(TransitionFrame.BlackFrame, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {BackgroundTransparency = 1})

					task.wait()

					Tween:Play()
					
					task.wait(2)
					
					AudioOut:Destroy()
					
				end
			end
		end
	end
end)

If anybody spots any issues because I’m too clueless to realize what I did wrong, please let me know. I don’t primarily do scripting, I’ve only gotten into it in the last few months after years of trying and now I’m finally at a level where I can make a mostly functional game, so if I made some rookie mistake, please excuse that.

Regardless, thank you for your time, patience, and I hope you have a great rest of your day.

2 Likes

You haven’t specified which part of these scripts is having problems.

2 Likes

“MoveToIntroCam1” the lines at 84 and 85 they just don’t fire for whatever reason. Sorry, was in a small hurry so I forgot to mention what was going wrong.

1 Like

What about the code that follows? Does it continue to work?

1 Like

MoveToIntroCam2 and PlayIntro all of that works flawlessly, no errors in the output, no other issues at all. Also Ziff thank you so much for replying to me on 2 separate posts you didn’t have to do that, means a lot to me.

1 Like

Where is your LocalScript located?

1 Like

In ReplicatedStorage and is then cloned and parented to the players involved

You might be experiencing a timing issue

What confuses me is the rest of the script runs fine and I can see via server it’s parented fine, I’m not sure how or what the issue is :frowning: sorry it’s 4:44AM for me I’m exhausted .

:backhand_index_pointing_up:

You’re using a lot of task.wait on both sides. Receiving a new client event doesn’t cancel an already running thread, so you have to find a way to cancel the delays. The task library offers functions to deal with that, such as task.cancel which can prevent delayed or suspended threads from proceeding.

task | Documentation - Roblox Creator Hub

If the timing isn’t the problem, though, then it might be a problem with the setup in some way.

1 Like

Consider setting a breakpoint and stepping through the code manually.

2 Likes

I am reading that you should use a timeout when you use Active in rounds b/c it can cause issues on rejoining.

local Active = script:WaitForChild("Active", 5)

if the object "Active" is not replicated from the server to the client before the script attempts to reference it, especially upon rejoining a round

1 Like

I see, sorry I used to use wait() but someone told me to use task.wait() to make sure everything works fine, I don’t want anything overlapping so I’ll look into that, thank you Marked.

1 Like

Good idea, I’ve never even used Breakpoints LOL

Active is a bool under the script at all times that when activated/set to true that’s when the script runs. Again that’s not the issue since, the rest of the script works fine, it’s JUST the part of “MoveToIntroCam1”,

First Time Playing

You and another player start the round, black transition, you teleport to a room that gets cloned from ServerStorage, and parented into the workspace, you then have a block that is used as a camera where Player1 plays some animation, the “intro” sequence of who you’re playing against. Black transition and then Player2 repeats Player1’s actions. Once both players play their intro, they are taken to a room, and then the game begins.

Second Time Playing

All events work the same, except the Black Screen and the entire function titled “MoveToIntroCam1” on the server just does not run whatsoever. I have the several print functions on the local to indicate what plays where and it just doesn’t fine at all. As if the Local never got anything, and then to make the situation weirder, the REST of the script, “PlayIntro”, “MoveToIntroCam2”, all of that works as intended. It’s JUST “MoveToIntroCam1”.

Sorry if I made some sort of dumb mistake, as I said I am not even close to being “good” at scripting, jack of all trades, master of none, I animate, model, script, do UI, make music, all of it, but I am far from the best at all of it.

I looked into task.cancel(), are you suggesting I basically put this somewhere at the end of the script to end it that way? If I’m understanding it properly. The documentation isn’t too clear to me.

How are you starting the second round? Like, specifically, what steps - in order - do you do to make the second round start. Read through the code and I don’t see anything that would cause another round to occur, wondering if you are doing it manually or is there more code that handles that part?

1 Like

you don’t turn debounce to true ever at all

1 Like

This won’t fix your problem but you should be using elseif instead of else if.

2 Likes

Not in that script, that script starts the round, separate script separate everything, on the second beginning of a round, the second time you want to play, the intro fails on me.