I have my local script in starterplayerscripts set to make a GUI and put it in playerGUI. Everytime the Character dies, the gui goes away. How do I make it so the GUI stays or just reappears when the player respawns?
local player = game.Players.LocalPlayer local gui = Instance.new('ScreenGui',player.PlayerGui) local frame = Instance.new('Frame',player.PlayerGui) local textlbl = Instance.new('TextLabel',player.PlayerGui) local health = Instance.new('IntValue',player) ----------------------------------------------------------------------------------------------------------------- gui.Name = 'HP' frame.Name = 'HlthPt' frame.Parent = player.PlayerGui.HP textlbl.Parent = player.PlayerGui.HP.HlthPt health.Name = 'health' health.Value = 250 frame.Size = UDim2.new(0,250,0,23) frame.Position = UDim2.new(0.705, 0,0.919, 0) frame.BackgroundColor3 = Color3.new(0,0,0) textlbl.Size = UDim2.new(0,250,0,23) textlbl.Position = UDim2.new(0.001, 0,0.004, 0) textlbl.BackgroundColor3 = Color3.new(0,198,0) textlbl.Text = player.health.Value.. '' .. '/250' player.health.Changed:connect(function() textlbl.Size = UDim2.new(0,player.health.Value,0,23) textlbl.Text = player.health.Value..''..'/250' if player.health.Value <= 166 and player.health.Value >= 83 then textlbl.BackgroundColor3 = Color3.new(217,217,0) elseif player.health.Value <= 83 then textlbl.BackgroundColor3 = Color3.new(227,0,0) else textlbl.BackgroundColor3 = Color3.new(0,198,0) end if player.health.Value > 250 then player.health.Value = 250 elseif player.health.Value < 0 then player.health.Value = 0 end if player.health.Value <= 0 then player.Character.Head:remove() end end)
ScreenGUIs have a property called ResetOnSpawn. Somewhere in your code, you should put:
gui.ResetOnSpawn = true
The StarterGui has a property called ResetPlayerGuiOnSpawn. If this property is set to false, then the GUIs will not be removed or reset when the character dies.
Hope that helped