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
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
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
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