I need to change BoolValues' values everytime a player dies from a local script

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to be able to change the values of Boolvalues everytime the Character dies from a local script

  2. What is the issue? After he dies for the first time, Humanoid.Died stops working

  3. What solutions have you tried so far? None, i don’t know what could solve this problem.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local ARRAY = {QCooldown2,ECooldown2,RCooldown2,QERCooldown} -- BoolValues
local Human = nil
local HumanoidDied = function()
	game.ReplicatedStorage.StuffFalse:FireServer(ARRAY) -- Changes the values of the instances in the array
	local variable = true
	while variable do
		wait(1)
		if Player.Character then
			if Player.Character.Humanoid.Health <= 0 then
				local humanoid = Player.Character.Humanoid
				return humanoid
			end
		end
	end
end

if not Player.Character then Player.CharacterAdded:wait() end
Human = Player.Character:WaitForChild("Humanoid")

local DeathCycle = coroutine.wrap(function()
	while true do
		print(Human, Human.Parent)
		Human.Died:wait()
		Human = HumanoidDied()
	end
end)
DeathCycle()

Screenshot_1
Dying again doesn’t do anything.

Where is your LocalScript at? If you have it in StarterPlayerScripts once the character dies the first time, that humanoid variable will still be referencing to that dead humanoid, so even after you respawn, your variable will now be nil and the event won’t fire. But if you have it in StarterCharacterScripts, whenever you die and your character respawns, all LocalScripts will reset and re-run so everything would be in place, and the event would properly fire again.

I need it to be in StarterPlayerScripts

Not sure why that’s a must, but if it’s 100% unavoidable, you can always do this:

local player = game.Players.LocalPlayer
local char, humanoid, connection

local function redoConnection()
	char = player.Character or player.CharacterAdded:Wait()
	humanoid = char:WaitForChild("Humanoid")
	
	connection = humanoid.Died:Connect(function()
		--Code for dying.
		redoConnection()
	end)
end

redoConnection()

That’ll make sure your variables reference to the correct instances, but you see how ugly it gets, and I am not 100% if that works because I didn’t test it. But if it does, I still highly recommend you switch to StarterCharacterScripts because you are executing code refering the Character not the Player.

1 Like

it’s not 100% unavoidable but i’d prefer it that way, thanks for the help

No problem, but make sure that code works first.

you can’t do connection:Disconnect() since connection == nil

Oh right, then you can just remove that connection:Disconnect() line. I added it just in case.

Aight dude, this ain’t working, i’ll try to fit the script in StarterCharacterScripts