Hello everyone!
I found a strange error I have never seen before.
I am trying to do a new Gui system that saves your Guis on death.
This my first try to make something like this.
Here is the local script ( in the StraterPlayerScripts ) :
local Gui = workspace.Guis
local lp = game.Players.LocalPlayer
lp.CharacterAdded:Connect(function()
Gui.Parent = lp.PlayerGui
function OnDeath()
if lp.Character:WaitForChild("Humanoid").Health == 0 then
local clone = Gui:Clone()
repeat wait()
until
lp.Character:WaitForChild("Humanoid").Health == 100
clone.Parent = lp.PlayerGui
end
end
lp.Character:WaitForChild("Humanoid").Changed:Connect(OnDeath)
end)
It should copy the Gui when the local player’s character dies and put it when it respawns, in this way keeping the Gui the way it was.
I know the script is not so good and clever but I just want to know what cause the error.
Thank you if you want to help!
Here’s a better approach, reference a variable to check for the Gui after you put it in ReplicatedStorage to check if you can re-parent the updated one or not
Try putting this it in StarterCharacterScripts:
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local Character = script.Parent
local Gui = workspace.Guis
local Humanoid = Character:WaitForChild("Humanoid")
local GuiCheck = game.ReplicatedStorage:FindFirstChild("Guis")
if GuiCheck then
GuiCheck.Parent = PlayerGui
else
Gui.Parent = PlayerGui
local function onDeath()
local clone = Gui:Clone()
clone.Parent = game.ReplicatedStorage
end
Humanoid.Died:Connect(onDeath)
end