CollectionService/Tag System to display GUI on player's screen not working

So, I’m trying to utilize the Collection/Tag system to reduce lag. My current script does create a proximity prompt in the object, but doesn’t make the GUI visible on the player’s screen when activated. I’m not used to using the Collection/Tag service so my script will most likely be poor in quality. (Also I forgot if I already made a topic on this, forgive me if I have-)

Here’s the current script:

local ServerScriptService = game:GetService("ServerScriptService")
local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local Players = game:GetService("Players")
local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local GUI = StarterGui:GetChildren()
local Modules = ServerScriptService:WaitForChild("Modules")
local Engine = require(Modules:WaitForChild("Engine"))

local Connection = {}

function applyCode(Inst)
	if not Inst:IsA("BasePart") then return end
	Connection[Inst] = {}
	local ProximityPrompt = Instance.new("ProximityPrompt")
	ProximityPrompt.ActionText = Inst:GetAttribute("ActionText")
	ProximityPrompt.ObjectText = Inst:GetAttribute("ObjectText")
	ProximityPrompt.Parent = Inst
	table.insert(Connection[Inst], ProximityPrompt.Triggered:Connect(function(Player)
		if Inst:GetAttribute("Disabled") then return end
		if not GUI:FindFirstChild(Inst:GetAttribute("GUIName")) then return end
		GUI[Inst:GetAttribute("GUIName")].Frame.Visible = true
	end))
end

task.spawn(function()
	local Tagged = CollectionService:GetTagged("LookAtPhoto")
	for count=1, #Tagged do
		local Inst = Tagged[count]
		task.spawn(function()
			applyCode(Inst)
		end)
	end
end)

CollectionService:GetInstanceAddedSignal("LookAtPhoto"):Connect(function(Inst)
	task.spawn(function()
		applyCode(Inst)
	end)
end)

CollectionService:GetInstanceRemovedSignal("LookAtPhoto"):Connect(function(Inst)
	if not Connection[Inst] then return end
	for count=1, #Connection[Inst] do
		local con = Connection[count]
		con:Disconnect()
	end
	Connection[Inst] = nil
end)

And here’s the Attributes in the part:
Screenshot (255)

Any n all help is appreciated and let me know if I should provide more information.

1 Like

Bumping this because I sadly haven’t found a solution.

1 Like

Tried to change this line

GUI[Inst:GetAttribute("GUIName")].Frame.Visible = true

to

GUI[Inst:GetAttribute("GUIName")].Enabled = true

But still no GUI is popping up. I’ll keep trying to find a solution.

1 Like

Finally figured it out. The GUI themselves shouldn’t be Enabled while having the frame Visibility be true. The only problem with this is that the GUI will stay on-screen if the player doesn’t exit out of it and happens to die or reset. Not a huge issue. I also added some lines so that the part plays a page flipping sound, this isn’t necessary so you can delete it if you wish.

A video of it in action:

The Script:

local ServerScriptService = game:GetService("ServerScriptService")
local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local Players = game:GetService("Players")
local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local Docs = StarterGui
local Modules = ServerScriptService:WaitForChild("Modules")
local Engine = require(Modules:WaitForChild("Engine"))

local Connection = {}

function applyCode(Inst)
	if not Inst:IsA("BasePart") then return end
	Connection[Inst] = {}
	local ProximityPrompt = Instance.new("ProximityPrompt")
	ProximityPrompt.ActionText = Inst:GetAttribute("ActionText")
	ProximityPrompt.ObjectText = Inst:GetAttribute("ObjectText")
	ProximityPrompt.Parent = Inst
	table.insert(Connection[Inst], ProximityPrompt.Triggered:Connect(function(Player)
		if Inst:GetAttribute("Disabled") then return end
		if not Docs:FindFirstChild(Inst:GetAttribute("GUIName")) then return end
		Docs[Inst:GetAttribute("GUIName")].Enabled = true
		Docs[Inst:GetAttribute("GUIName")]:Clone().Parent = Player.PlayerGui

		local Sound = script:WaitForChild("Open"):Clone()
		Sound.Parent = Inst
		Sound:Play()
	end))
end

task.spawn(function()
	local Tagged = CollectionService:GetTagged("ViewGUI")
	for count=1, #Tagged do
		local Inst = Tagged[count]
		task.spawn(function()
			applyCode(Inst)
		end)
	end
end)

CollectionService:GetInstanceAddedSignal("ViewGUI"):Connect(function(Inst)
	task.spawn(function()
		applyCode(Inst)
	end)
end)

CollectionService:GetInstanceRemovedSignal("ViewGUI"):Connect(function(Inst)
	if not Connection[Inst] then return end
	for count=1, #Connection[Inst] do
		local con = Connection[count]
		con:Disconnect()
	end
	Connection[Inst] = nil
end)