I am trying to make a GUI that appears and says random text when you die, that all works, but the problem is, when it disables, it never enables again (unless I do it manually), how can I solve this?
Here’s the code:
local player = game:GetService("Players").LocalPlayer
local playerGui = player.PlayerGui
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
playerGui.LolGui.Enabled = true
wait(3)
playerGui.LolGui.Enabled = false
end)
That has absolutely nothing to do with the issue we’re talking about. Also, your reply seems to be generated by a certain service offered by OpenAI, so please consider what you’re replying.
I think the problem is when the code runs, it sets an enable for the LolGui to 3 seconds.
After the 3 seconds, I believe the code is making the GUI disable for 4 seconds, but it’s hard to tell, because there is no line to end the disable part.
When the player dies, the character is removed, meaning the connection to the humanoid is destroyed.
Try putting the humanoid.died event connection inside another connection to detect whenever the character loads
-- Don't wait for the character beforehand.
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(...)
end)
Try this it does the exact same thing but its less cluttered
local player = game:GetService("Players").LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
playerGui.LolGui.Enabled = true
wait (5)
playerGui.LolGui.Enabled = false
end)