How to make when a player dies It should change Instance.new bool value

Greetings, Developers! I need to change the bool value within the player script when the player dies. I have a script that creates a new bool value when the player enters the game, and I need another script to change the value to false when the player dies. Hope I explained it more clearly this time.

This script creates new value

local PM = game.Workspace.Arena.Give
local SZ = game.Workspace.Arena.remover.Remover
local UN = game.Workspace.Arena.Untouch

game.Players.PlayerAdded:Connect(function(plr)
	local PVP = Instance.new("BoolValue")
	PVP.Name = "Isworking"
	PVP.Value = false
	PVP.Parent = plr
end)


PM.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			plr.Isworking.Value = true
	end
end)

PM.TouchEnded:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		plr.Isworking.Value = false
	end
end)

The script which should check It

game.Players.PlayerAdded:Connect(function(plr)
	task.spawn(function()
		local player = plr
		repeat task.wait() until player.Character
		local humanoid = player.Character:FindFirstChild("Humanoid")
		humanoid.Died:Connect(function()
			plr:WaitForChild("Isworking").Value = false
		end)
	end)
end)

Explain further. Does the value not change?

game.Players.PlayerAdded:Connect(function(plr)
		local player = plr
		local humanoid = player.Character:FindFirstChild("Humanoid")
		humanoid.Died:Connect(function()
			plr:WaitForChild("Isworking").Value = false
		end)
end)

Are you receiving any errors??

1 Like

idk lol, i just did this without using roblox studio

Nevermind, I thought you were the OP. :sweat_smile:

1 Like

What does OP mean??? I think my script should work because very reasonable

OP means Original Poster, just didn’t look at the names.

1 Like

No, It does not give any error but It does not change value

This script you provided does not work sadly.

game.Players.PlayerAdded:Connect(function(plr)
		local player = plr
		local humanoid = player.Character:FindFirstChild("Humanoid")
		humanoid.Died:Connect(function()
            print(plr:WaitForChild("Isworking"))
			plr:WaitForChild("Isworking").Value = false
            print("Died")
		end)
end)

Just checking if its the function not working. What script is this is by the way, localscript or normal script

It works perfectly fine for me. Try doing these;

1 - Check If you using client for died function, if so make it server or use remote event
2 - After player dies, system still checks if player touching the area and changes the “Isworking” value to true, do something like this; “if Humanoid.Health > 0 then” so it will only change the value if player is alive. Hope it’s works for you.
image