Values aren't working when Player Refreshes

I have a transition Fade script and it works when a player joins the game, but when a player is refreshed, it doesn’t work. My assumption is that the “Fade and Fade2” values don’t change with the player refreshing. Any help is appreciated.

If it helps, this is a local script in “ReplicatedFirst”.

local Event = game:GetService("ReplicatedStorage"):WaitForChild("BlackFade")
local Player = game:GetService("Players").LocalPlayer
local theplayer = game.Players.LocalPlayer
local Fade = Player:WaitForChild("PlayerGui"):WaitForChild("BlackFade").tframe
local Fade2 = Player:WaitForChild("PlayerGui"):WaitForChild("WhiteFade").tframe
local Info = TweenInfo.new(3)
local Info2 = TweenInfo.new(9)
local tween = game:GetService("TweenService"):Create(Fade,Info,{BackgroundTransparency=0})
local tween2 = game:GetService("TweenService"):Create(Fade2,Info,{BackgroundTransparency=0})
local closetheshopup = game:GetService("TweenService"):Create(Fade2,Info2,{BackgroundTransparency=1})
local paryers = {}
local AliveTeam = game.Teams.Alive
Event.OnClientEvent:Connect(function()
	Fade.Visible = true
	tween:Play()
	tween.Completed:Wait()
	Fade.Transparency = 1
	wait(18)
	Fade2.Visible = true	
	tween2:Play()
	tween2.Completed:Wait()
	wait(1)
	for i, player in pairs(AliveTeam:GetPlayers()) do
		if player then
			table.insert(paryers,player)
		end
	end
	for i, player in pairs(paryers) do
		if player then
			player.CameraMode = Enum.CameraMode.LockFirstPerson
		end
	end
	closetheshopup:Play()
	closetheshopup.Completed:Wait()
	Fade.Visible = false
	Fade2.Visible = false
end)

That is could be because when the player resets, the original gui gets deleted and a new one is copied from “StarterGui” into the players “PlayerGui”.
You have to update you variable, when the player respawns!
I would do it like this:

local Fade
local Fade2
Player.CharacterAdded:Connect(function()
	Fade = plr:WaitForChild("PlayerGui"):WaitForChild("BlackFade").tframe
	Fade2 = plr:WaitForChild("PlayerGui"):WaitForChild("WhiteFade").tframe
end)

or like this

Player.ChildAdded:Connect(function(child)
	if child.Name == "PlayerGui" then
		--update your variables here
	end
end)
1 Like

It doesn’t work still. I added this:

Player.CharacterAdded:Connect(function()
	Fade = Player:WaitForChild("PlayerGui"):WaitForChild("BlackFade").tframe
	Fade2 = Player:WaitForChild("PlayerGui"):WaitForChild("WhiteFade").tframe
end)

Wait, you were correct @Nycrov. All it is that I forgot is to put the tween info in the function. I had to make it like this:

Player.CharacterAdded:Connect(function()
	Fade = Player:WaitForChild("PlayerGui"):WaitForChild("BlackFade").tframe
	Fade2 = Player:WaitForChild("PlayerGui"):WaitForChild("WhiteFade").tframe
	tween = game:GetService("TweenService"):Create(Fade,Info,{BackgroundTransparency=0})
	tween2 = game:GetService("TweenService"):Create(Fade2,Info,{BackgroundTransparency=0})
	closetheshopup = game:GetService("TweenService"):Create(Fade2,Info2,{BackgroundTransparency=1})
end)