Idk, why does this not work correctly? I want to show to player a GUI after the respawned but it’s not working, even the print("broken") doesn’t show up.
EDIT: I moved the Local Script to the StarterPlayerScripts, but its still not working.
local Menu = game.Players.localPlayer.PlayerGui.StaminaBarGui
local Players = game:GetService("Players")
local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
Player.CharacterAdded:Wait()
Menu.Enabled = true
print("broken")
end)
I think what’s happening is that the localscript is getting deleted before it can print. Try removing the wait(5), or as others have said set the ResetOnSpawn property of the ScreenGui to false.
local Players = game:GetService("Players")
local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
Player.CharacterAdded:Wait()
local Menu = game.Players.localPlayer.PlayerGui.StaminaBarGui
Menu.Enabled = true
print("not broken")
end)
Basically why it didnt work is because you defined the Menu before the player died, so the ScreenGui Resets if you die and the Menu doesnt exist anymore because ResetOnSpawn is turned on. If you defined the Menu after the Player.CharacterAdded:Wait() then it will use the new ScreenGui .
I hope u understand im not best english speaker. i hope it even works lol