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