GUI not showing up when accessory is equipped

  1. What do you want to achieve?
    GUI becomes visible when accessory is equipped

  2. What is the issue?
    The rest of the script is working but the GUI part isnt

  3. What solutions have you tried so far?
    I tried modifying the script while referencing other scripts i made

here is the script

local ServerStorage = game:GetService("ServerStorage") 
local RealHats = ServerStorage.RealHats:GetChildren() local FakeHats = workspace:WaitForChild("FakeHats"):GetChildren() -- References the "FakeHats" folder inside of the Workspace and turns it into a table that can be looped through so every item does not need to be referenced manually

local function GiveHat(player, FakeHat) -- 
    local Character = player.Character or player.CharacterAdded:Wait() 
    local HatCheck = Character:FindFirstChild(FakeHat.Name)
    local Humanoid = Character:WaitForChild("Humanoid")
    local ColorWheel = FakeHat:FindFirstChild("ColorWheel")
 

    if not HatCheck then 
        for i, RealHat in pairs(RealHats) do
            if FakeHat.Name == RealHat.Name then 
                local ClonedHat = RealHat:Clone()
                Humanoid:AddAccessory(ClonedHat) 
                if ColorWheel then
                    local clonedColorWheel = ColorWheel:Clone()
                    clonedColorWheel.Parent = game.StarterGui.ClothesGui
                    clonedColorWheel.Visible = true
                end
            end 
        end 
    end 
end 
for i, FakeHat in pairs(FakeHats) do
    local Handle = FakeHat:FindFirstChild("Handle")
    local ClickDetector = Handle:FindFirstChildOfClass("ClickDetector")
  

    if Handle and ClickDetector then 
       ClickDetector.MouseClick:Connect(function(player) 
            GiveHat(player, FakeHat)
        end)
end 

this script basically equips an accessory on you if you click on the accessory you want to equip. In conclusion , I wanted it so that if you equip an accessory a gui template inside of the fakehat gets cloned and becomes visible. So the problem is that the gui wont showup on my screen.

(im sorry if this is unclear, english isnt my first language)

You are parenting the ui object into the StarterGui, rather than the PlayerGui

The StarterGui contains guis that will be cloned into the PlayerGui when a player joins the game, parenting a gui to the starter gui during run time does nothing

Instead, you need to parent it to this:

clonedColorWheel.Parent = player:WaitForChild("PlayerGui")

Hope this helps.

1 Like

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