Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Keeping a GUI on a users screen after respawning without using ResetPlayerGuiOnSpawn?

So far, it's slightly possible, just need help if anyone else has ever made this or made it way better than my bad nasty loop.

if script.Parent and script.Parent:findFirstChild("Locked")==nil and script.Parent.ClassName=="ScreenGui" then
	function UnArchive(p)
		pcall(function()
			p.Archivable=false;
		end)
		pcall(function()
			for i,v in ipairs(p:GetChildren()) do
				UnArchive(v)
			end
		end)
	end
	function TransferAll(mainlocation,item)
		pcall(function()
			print(item.Name.." : "..item:getFullName())
			item.Parent=mainlocation
		end)
		pcall(function()
			for i,v in ipairs(item:GetChildren()) do
			TransferAll(item,v)
			end
		end)
	end
	local lock=Instance.new("StringValue",script.Parent)
	lock.Name="Locked"
	local gui=script.Parent
	UnArchive(gui)
	script.Parent=nil
	local me=script.Parent
	function AlwaysChecking()
		for a=1,25 do
			print("Checking "..gui:GetFullName())
			if gui.Parent~=game.Players.LocalPlayer.PlayerGui then
				TransferAll(game.Players.LocalPlayer.PlayerGui,gui)
				--gui.Parent=game.Players.LocalPlayer.PlayerGui
			end
			wait(.1)
		end
	end
	gui.Changed:connect(function()
		print("Fired")
		AlwaysChecking()
	end)
	gui.AncestryChanged:connect(function()
		print("Fired2")
		AlwaysChecking()
	end)
end

1 answer

This is how we did it in Valkyrie

local overlay = script.Parent.ValkyrieOverlay;
overlay = overlay:Clone();
local Player = game.Players.LocalPlayer;
local CharBind = function(c)
	if not Player.PlayerGui:FindFirstChild("ValkyrieOverlay") then
		overlay.Parent = Player.PlayerGui;
		overlay.Name = "ValkyrieOverlay";
	end;
	local humanoid = c:FindFirstChild("Humanoid")
	if not humanoid then
		-- Look for a Humanoid class
		local int = c:GetChildren();
		for i=1,#int do
			local v = int[i];
			if v:IsA("Humanoid") then
				humanoid = v;
				break;
			end;
		end;
		while not humanoid do
			-- Start listening
			local v = c.ChildAdded:wait();
			if v:IsA("Humanoid") then
				humanoid = v;
				break;
			end;
		end;
	end;
	humanoid.Died:wait();
	overlay.Parent = script;
end
Player.CharacterAdded:connect(CharBind);
if Player.Character then coroutine.wrap(CharBind)(Player.Character) end;
overlay.Parent = Player:WaitForChild("PlayerGui");

Source

1 comment

0

My goodness, looks a lot more efficient than my loop. Will go ahead and give this a try. However, I have a client sided script that'll always be showing, since the client script is nilled, so I'll just need to monitor the Died event.

This discussion is preserved as it was. New answers, comments, and votes are closed.