Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

This script should be toggled after the humanoid dies, but instead it remains on?

Asked by 4 years ago
Edited 4 years ago

This question has been solved by the original poster.

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?

1 answer

Log in to vote
1
Answered by 4 years ago

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)
0
if anyone knows a more optimized way of doing this please lmk DaBagelBoy 90 — 4y
Ad

Answer this question