CollectionService/Tag System for GUIs not working

I’m basically just trying to utilize this system to reduce lag instead of having to copy and paste the script and ProximityPrompt every time I want an object to be able to open a GUI. The 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 this service so please excuse me if the script is poor in quality.

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:WaitForChild("Photos")

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("LookAtPicture")
    for count=1, #Tagged do
        local Inst = Tagged[count]
        task.spawn(function()
            applyCode(Inst)
        end)
    end
end)

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

CollectionService:GetInstanceRemovedSignal("LookAtPicture"):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)

Any and all help is appreciated.

3 Likes

I’m sure it is a bit late to help you but just in case someone else comes across this looking to find a solution what I have found is that if I tag items in the StarterGui it does not carry over when copied to the PlayerGui. Therefore I have a script in StarterCharacterScripts that sets the tags I need and it works.

2 Likes

It really has been a while hasn’t it? Here’s a fixed version of the script as well as the attributes that the ViewGUI Part has!

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)

Screenshot (1930)

The ActionText and ObjectText attributes explain themselves. A Disabled boolean in case there’s an event where you’d like the GUI to be unable to be activated, and of course the GUIName is the name of the GUI that you want to pop up when it’s activated. Don’t forget to add a ViewGUI tag to your tags list and give your selected Part the tag.

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