GUI not tweening on the second time

So I have a transition circle that tweens whenever a player dies. View video below:
https://streamable.com/wzuohh

However, as seen in the video, my problem is that it only tweens the first time the player has died. I checked it’s position afterwards, and that’s not the problem.

Here is the script I used:

local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild("Humanoid")

local image = script.Parent.Transition
local frame = script.Parent.Frame

hum.Died:Connect(function()
	wait(1)
	
	image:TweenSizeAndPosition(UDim2.new(0.033,0,0.057,0), UDim2.new(0.5,0,0.5,0), 1)
	
	wait(1)
	
	for i = 1,-0.05,-0.2 do
		frame.BackgroundTransparency = i
		wait()
	end
	
	wait(4)
	
	for i = 0,1.05,0.2 do
		frame.BackgroundTransparency = i
		wait()
	end
	
	image:TweenSizeAndPosition(UDim2.new(1.2,0,2.1,0), UDim2.new(0.5,0,0.5,0), 1)
end)

Keep in mind, this ScreenGui does not reset on spawn.

Any help will be greatly appreciated!

Try and add a character added so that every time the character is added, the function fires. So

game.Players.PlayerAdded:Connect(function(player)
player.Character.CharacterAdded:Connect(function(char)
hum.Died:Connect(function()
-- your code
end)
end)
end)

Did not work. The transition doesn’t even show now lol

Weird, it should. Try moving the humanoid variable in between CharacterAdded and Hum.Died

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
    local humanoid = char:WaitForChild("Humanoid")

    if humanoid then
    humanoid.Died:Connect(function()
    -- code
     end)
   end
 end)
end)

Yep. I just tried that and nothing plays.

I don’t think the PlayerAdded event will be called, So the CharacterAdded won’t be called either, Try this:

local Plr = game:GetService("Players").LocalPlayer;
local Char = Plr.Character or Plr.CharacterAdded:Wait();
local Hum = Char:WaitForChild("Humanoid");

--<Now Call The Character Added From The Already Defined Player
Plr.CharacterAdded:Connect(function(Character)
    Char = Character;
    Hum = Character:WaitForChild("Humanoid");
end)

Wait, I just found a solution haha!

Basically, since the code still runs after the player respawns (the gui doesn’t reset on spawn), I just cloned the local script and destroyed the original one.

Thanks for all the help though!

1 Like

But then if it resets on spawn, wouldn’t that defeat the purpose of the transition effect?

That’s why I set that part to false. But yeah