Gui transition isnt working on switching

So i made a script where you can switch between 2 characters, lets call them Brain1 and Brain2 , the switching script works just fine and the last thing remaining is a gui when switching where the screen goes completely black then fades out when pressing a button, but i tried everything to make it work but it just doesnt work, i tried the same script on my real player character and it works, but when switching to brain1 to brain2 or vice versa it doesnt work.

here is the code i use on my character

local function FadeIn()
	for i = 1, 0, -0.02 do
		wait(0.02)
		script.Parent.Transparency = i
	end
	script.Parent.Transparency = 0
end

local function FadeOut()
	for i = 0, 1, 0.02 do
		wait(0.02)
		script.Parent.Transparency = i
	end
	script.Parent.Transparency = 1
end
wait(5)
FadeIn()
wait(5)
FadeOut()

This code works perfectly.

This code that i use for swithcing

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local Brain1 = workspace:WaitForChild("Brain1")
local Input = Enum.KeyCode.E
local Debounce = true
local Camera = workspace.CurrentCamera
local Brain2 = workspace:WaitForChild("Brain2")
local inBrain1 = true
local Input2 = Enum.KeyCode.Q

local PlayerScripts = Player:WaitForChild("PlayerScripts")
local PlayerModule = require(PlayerScripts:WaitForChild("PlayerModule"))

local Controls = PlayerModule:GetControls()

UserInputService.InputBegan:Connect(function(input,IsPressed)
	if Debounce then
		Debounce = false	
		if input.KeyCode == Input and inBrain1 == false then
			inBrain1 = true
			IsPressed = true
			print("brain1")
			game.Players.CharacterAutoLoads = false
			Controls:Disable()
			task.wait(2)
			Player.Character = Brain1
			Camera.CameraSubject = Brain1.Humanoid
			Controls:Enable()
		end

		if inBrain1 == true and input.KeyCode == Input2 and Player.Character == Brain1 then
			inBrain1 = false
			print("brain2")
			game.Players.CharacterAutoLoads = false
			Controls:Disable()
			task.wait(2)
			Player.Character = Brain2
			Camera.CameraSubject = Brain2.Humanoid
			Controls:Enable()
		end
		
		wait(1)
		Debounce = true
		game.Players.CharacterAutoLoads = true
	end
end)

This code is when i join the game to switch to brain1

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local StillInMain = true
local Brain1 = workspace:WaitForChild("Brain1")
local Brain2 = workspace:WaitForChild("Brain2")
local Camera = workspace.CurrentCamera

Player.CharacterAdded:Connect(function(plr)
	print(plr.Name)
	print("koko")
	while StillInMain do
		wait(5)
		Player.Character = Brain1
		Camera.CameraSubject = Brain1
		print("waiting")
		if Player.Character == Brain1 or Player.Character == Brain2 then
			StillInMain = false
		end
	end
end)

is there a way to fix this problem or is it because playergui only works on real players since Brain1 and Brain2 are not real players?

Edit: i forgot to say that i deleted the script where it fades in and out since it didnt work but it was like if if input.KeyCode == Input or input.KeyCode == Input2 then then the fade in fade out code (using for loop).