How can I make it so that when the player dies the gui goes back into the player's PlayerGui?

Hello!

I was working on my game until I ran into a problem.

I was trying to make it so that everytime the player dies an admin gui i made gets cloned back into their playergui.

But the problem is that the script only worked once.
After a third death the script won’t work anymore.

Script
task.wait(2)

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character

Character.Humanoid.Died:Connect(function()
	task.wait(7)
	game:GetService("ReplicatedStorage"):WaitForChild("AdminGUI", 1000):Clone().Parent = Player.PlayerGui
end)
The way I clone the admin gui to the player once
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GetAdminPanelEvent = ReplicatedStorage:WaitForChild("GetAdminPanelEvent", 1000)

GetAdminPanelEvent.OnServerEvent:Connect(function(Player)
	local AdminGui = game:GetService("ReplicatedStorage"):WaitForChild("AdminGUI")
	AdminGui:Clone().Parent = Player.PlayerGui
	
end)

Try this for your script

task.wait(2)

local Player = game:GetService("Players").LocalPlayer

Player.CharacterAdded:Connect(function()
	game:GetService("ReplicatedStorage"):WaitForChild("AdminGUI", 1000):Clone().Parent = Player.PlayerGui
end)


1 Like

Damn! Thanks a lot!
Oddly enough, I tried the same way before but it didn’t work. But it doesn’t matter anymore.
Again, thank you! : D

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.