How to know "when" the object/character is no longer exist

So I’m trying to make a script that lets players carry the player when the player is knocked. The problem I’m trying to fix is to release the player from getting carried ( animations, ragdolls, etc ) when the Carrying or GettingCarried Character is left. In order to do that, according to the script I made, it needs an object value of the knocked character and the carrying character. The function has to run either when the player that is carrying or being carried character is left so the character that is being carried or carrying do not left being getting stuck in a certain animation with anchored humanoid.

Each character has two values, Getting Carried and Carrying in which GettingCarried is the object value of the character carrying it and Carrying is the object value of the character you are carrying.

So my script is to detect when the Carrying or GettingCarried player is left. The problem is that it’s not detecting the value of the character when he leaves. ( I know that this cannot work this way cuz characters destroy first when the player is left )

So I tried Object Value to see if it updates when the player is left, This way is not working either.
If you know any way I can detect a value inside the player’s character when the player is left. Or from another existing character which is being carried or carrying?

My Code:

CCharacterStats.Carrying.Changed:Connect(function()
			print("CARRYING VALUE CHANGED PROCESSING")
			print(CCharacterStats.Carrying.Value)
			if CCharacterStats.Carrying.Value == nil then
				char.HumanoidRootPart.gripweld:Destroy()

				for i,v in pairs(char.Humanoid:GetPlayingAnimationTracks()) do
					v:Stop()
				end


				char.Humanoid.PlatformStand=false
				char.HumanoidRootPart.Anchored = false
				char.Humanoid.WalkSpeed = 16
				player.DevComputerMovementMode = Enum.DevComputerMovementMode.UserChoice

			end
		end)
		
		CCharacterStats.GettingCarried.Changed:Connect(function()
			print("GETTING CARRIED VALUE CHANGED")
			print(CCharacterStats.GettingCarried.Value)
			if CCharacterStats.GettingCarried.Value == nil then
				char.HumanoidRootPart.gripweld:Destroy()

				for i,v in pairs(char.Humanoid:GetPlayingAnimationTracks()) do
					v:Stop()
				end


				char.Humanoid.PlatformStand=false
				char.HumanoidRootPart.Anchored = false
				char.Humanoid.WalkSpeed = 16
				player.DevComputerMovementMode = Enum.DevComputerMovementMode.UserChoice
				
				if Humanoid.Health <= 20 and CCharacterStats.Knocked.Value == false then
					KnockPlayer(player)
				else
					UnKnockPlayer(player)
				end
			end
		end)

Couldn’t you keep the “knocked” character object? but just use a

for i,v in pairs() do

end

loop, and change set the transparency to 1? Then after the script runs that needs it, you can :Destroy() the object.

1 Like

I’m talking about getting the object value inside the Character when the Character left the game
Each characters store certain data of their partners, I need to get the Character’s partner value so I can say to its partner that he is gone.

You could use a objectValue and set it to the character before it gets deleted and add attributes (Using :SetAttribute(“Name”, Value) ) that contains the data that is required. OR you could put the character into ReplicatedSotrage whilst the data is being collected, then you can delete the character.