Im not sure how to approach this

Hello, im not quite sure on how to approach this situation, i’ve got a script that detects when the player dies, and when the time runs out all the values turn back to false, but i want it to do a check when the carry value is turned to false, the timer will stop until the carry turns back to true, but im not entirely sure on how to approach this. Can someone help me out? this is the code

	humanoid.Died:Connect(function()
			ragdollTrigger.Value = true
			character:FindFirstChild('Humanoid').Health = 5
			death.Value = true
			carry.Value = true
			task.wait(15)
			ragdollTrigger.Value = false
			death.Value = false
			carry.Value = false

		end)
	end
end
External Media

video for reference

1 Like

Not sure what you are referring to as the “timer”, is it task.wait, if so that is a wait. However to detect when carry changes you can use:

carry:GetPropertyChangedSignal("Value"):Connect(function()
	if carry.Value then -- if its true
		
	else
		
	end
end)

Is there any other part of your script that turns carry.Value to true?
Or does the timer start and stop each time the player is dead?

this is the enitre script if u want it

local Players = game:GetService("Players")

-- Function to handle player character setup
local function onCharacterAdded(character)
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end

	-- Ensure the "RagdollTrigger" value exists in the character
	local death = character:FindFirstChild('DeathCheck')
	local carry = character:FindFirstChild('IsCarriable')
	local ragdollTrigger = character:FindFirstChild("RagdollTrigger")
	if ragdollTrigger and ragdollTrigger:IsA("BoolValue") then

		-- Connect to the Died event
		humanoid.Died:Connect(function()
			ragdollTrigger.Value = true
			character:FindFirstChild('Humanoid').Health = 5
			death.Value = true
			carry.Value = true
			task.wait(15)
			ragdollTrigger.Value = false
			death.Value = false
			carry.Value = false

		end)
	end
end

-- Function to handle player added
local function onPlayerAdded(player)
	player:LoadCharacter(false)
end

-- Connect PlayerAdded event
Players.PlayerAdded:Connect(onPlayerAdded)

-- For existing players (in case the script is added mid-game)
for _, player in pairs(Players:GetPlayers()) do
	if player.Character then
		onCharacterAdded(player.Character)
	end
	player.CharacterAdded:Connect(onCharacterAdded)
end

You could store the timer in a variable and run task.cancel(variableName) on that variable.

local timer = nil
humanoid.Died:Connect(function()
	ragdollTrigger.Value = true
	character:FindFirstChild('Humanoid').Health = 5
	death.Value = true
	carry.Value = true
	timer = task.delay(15, function()
		ragdollTrigger.Value = false
		death.Value = false
		carry.Value = false
	end)
end)

carry.Changed:Connect(function(isCarrying)
	if isCarrying then
		if timer then task.cancel(timer); timer = nil end
	else
		timer = task.delay(15, function()
			ragdollTrigger.Value = false
			death.Value = false
			carry.Value = false
		end)
	end
end)


i’m getting an error with my code after using your solution, and its saying its missing ends,
tried to mess around with it and figure out where it needs them but no use

I removed your ends because I was getting errors myself lol,

local timer = nil
humanoid.Died:Connect(function()
	ragdollTrigger.Value = true
	character:FindFirstChild('Humanoid').Health = 5
	death.Value = true
	carry.Value = true
	timer = task.delay(15, function()
		ragdollTrigger.Value = false
		death.Value = false
		carry.Value = false
	end)
end)
end
end

carry.Changed:Connect(function(isCarrying)
	if isCarrying then
		if timer then task.cancel(timer); timer = nil end
	else
		timer = task.delay(15, function()
			ragdollTrigger.Value = false
			death.Value = false
			carry.Value = false
		end)
	end
end)

Try this maybe

External Media

Still doing the same thing as before even with the function, and i tweaked the code a little, it didnt work before with the code you provided

Im going to need to get gyozo man

yeah im getting gyazo to clip it

local Players = game:GetService("Players")

-- Function to handle player character setup
local function onCharacterAdded(character)
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end

	-- Ensure the "RagdollTrigger" value exists in the character
	local death = character:FindFirstChild('DeathCheck')
	local carry = character:FindFirstChild('IsCarriable')
	local ragdollTrigger = character:FindFirstChild("RagdollTrigger")
	if ragdollTrigger and ragdollTrigger:IsA("BoolValue") then

		-- Connect to the Died event
		local timer = nil
		humanoid.Died:Connect(function()
			ragdollTrigger.Value = true
			character:FindFirstChild('Humanoid').Health = 5
			death.Value = true
			carry.Value = true
			timer = task.delay(15, function()
				ragdollTrigger.Value = false
				death.Value = false
				carry.Value = false
			end)
		end)
		
		carry.Changed:Connect(function(isCarrying)
			if isCarrying then
				if timer then task.cancel(timer); timer = nil end
			else
				timer = task.delay(15, function()
					ragdollTrigger.Value = false
					death.Value = false
					carry.Value = false
				end)
			end
		end)
	end
end

-- Function to handle player added
local function onPlayerAdded(player)
	player:LoadCharacter(false)
end

-- Connect PlayerAdded event
Players.PlayerAdded:Connect(onPlayerAdded)

-- For existing players (in case the script is added mid-game)
for _, player in pairs(Players:GetPlayers()) do
	if player.Character then
		onCharacterAdded(player.Character)
	end
	player.CharacterAdded:Connect(onCharacterAdded)
end

I have copypasted your entire original code and just overwritted what was needed

This should work now

https://gyazo.com/a0a86cadc751d70607b92f99c98cf09d
used your newest code, and its still getting up after the time

i tried to figure out where the problem was coming from and it looks like the timer doesn’t get cancelled at all


image