I made a script to test if a toggle mechanism worked. This is what it was:
toggle = false game:GetService('Players').PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) character:WaitForChild("Humanoid").Died:Connect(function() toggle = true print("ToggledOn") toggle = false end) end) end) if toggle == false then print("ToggledOff") end
so originally toggle is equal to false. If the player dies, then toggle is equal to true which prints ("ToggledOn"). then it is reset, and toggle is equal to false again and it should print ("Toggledoff"). My problem is that it isn't printing Toggled off, only ToggledOn after the humanoid dies. Can someone help me with this?
I just found out that all I had to do was set the bottom part in a run service so that it loops every frame.
toggle = false game:GetService('Players').PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) character:WaitForChild("Humanoid").Died:Connect(function() toggle = true print("ToggledOn") toggle = false end) end) end) local RunService = game:GetService("RunService") RunService.Stepped:Connect(function() if toggle == false then print("ToggledOff") end end)