Why does the GUI that I created go away when the player respawns? It's coded to show when the player dies and to only go away when you click the close button.
It's a local script placed in starter player scripts. This is the code:
local players = game:GetService("Players") local player = players.LocalPlayer local debounce = false local messageGui, messageLabel, closeButton, humanoid -- Create the messageGui and its children function createMessageGui() if not messageGui then messageGui = Instance.new("ScreenGui") messageLabel = Instance.new("TextLabel") closeButton = Instance.new("TextButton") -- Add the messageGui to the player's PlayerGui messageGui.Parent = player:WaitForChild("PlayerGui") end -- Set properties for the message label messageLabel.Size = UDim2.new(1, 0, 0.1, 0) messageLabel.Position = UDim2.new(0, 0, 0, 0) messageLabel.BackgroundTransparency = 0.8 messageLabel.TextWrapped = true messageLabel.TextXAlignment = "Center" messageLabel.TextYAlignment = "Center" messageLabel.Parent = messageGui messageLabel.Visible = false -- Set properties for the close button closeButton.Size = UDim2.new(0.1, 0, 0.1, 0) closeButton.Position = UDim2.new(0.9, 0, 0, 0) closeButton.Text = "X" closeButton.Parent = messageGui closeButton.Visible = false -- Connect to the close button's MouseButton1Click event closeButton.MouseButton1Click:Connect(function() messageLabel.Visible = false closeButton.Visible = false end) end createMessageGui() -- Connect to the player's Chatted event player.Chatted:Connect(function(message) if debounce then player:Kick("You cannot type for 30 seconds after dying.") end end) -- Connect to the humanoid's Died event player.CharacterAdded:Connect(function(character) humanoid = character:WaitForChild("Humanoid") humanoid.Died:Connect(function() if debounce then return else debounce = true print("Player Died") messageLabel.Text = "You died! You can't chat for 30 seconds!" messageLabel.Visible = true closeButton.Visible = true wait(30) debounce = false end end) end)
UPDATE: T3_MasterGamer solved this problem by adding a
messageGui.ResetOnRespawn = false
when setting the properties. As I can't mark his comment as the answer I am updating my post instead. Thanks!
StarterPlayerScripts will only run once the player has joined, if you want it to run per respawn you can put it in StarterCharacterScripts.