Clothing change GUI not working

I’m trying to make a GUI to change the player’s clothing but the buttons aren’t working (probably because of the way I’m listening for button activation) and if I manually fire the event with valid arguments it sets the ID for the shirt and pants but they don’t appear on the avatar.

The scripts are functions in a client and a server module script, there’re no errors but the buttons just don’t do anything and the clothing changing just causes the clothing not to appear on the avatar.

I’ve searched devforum and google but none of the methods I’ve tried have worked.

--Server side

local Event = game:GetService("ReplicatedStorage").Event
	
	Event.OnServerEvent:Connect(function(Player, Uniform )
		warn(Player)
		local Character = Player.Character

		if Character == nil then
			warn("No character")
		else
			warn("Character")

			Character.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=" .. Uniform.Top
			Character.Pants.PantsTemplate = "http://www.roblox.com/asset/?id=" .. Uniform.Bottoms
		end
	end)
--Button detection
for _, Button in pairs(Buttons) do
		if Button == Buttons.Main then
			Button[1].Activated:Connect(function()
				warn("Main clicked")
				if GUI_Visible == false then
					for _, Button1 in pairs(Buttons) do
						Button1[1].Visible = true
					end
					GUI_Visible = true
				else
					for _, Button1 in pairs(Buttons) do
						Button1[1].Visible = false
					end
					GUI_Visible = false
				end
			end)
		else
			Button[1].Activated:Connect(function()
				warn(Button .. "Clicked")
				if Button[3] then
					local Event = game:GetService("ReplicatedStorage").Event
					Event:FireServer(Button.Uniform)
				else 
					GUI.Popup.Visible = true
					GUI.Popup.Alert:Play()
					wait(3)
					GUI.Popup.Visible = false
				end
			end)
		end
	end
--Buttons array 
local Buttons = {
		Main = {GUI.Uniforms},
		Student = {GUI.Uniform_Buttons.Student, Uniform = Uniforms.Student, Auth = true},
		Instructor = {GUI.Uniform_Buttons.Instructor, Uniform = Uniforms.Instructor, Auth = AuthLevel.InstructorAuth},
		Staff = {GUI.Uniform_Buttons.Staff, Uniform = Uniforms.Staff, Auth = AuthLevel.StaffAuth},
		Spectator = {GUI.Uniform_Buttons.Spectator, Uniform = Uniforms.Spectator, Auth = AuthLevel.SpectatorAuth},
		Executive = {GUI.Uniform_Buttons.Executive, Uniform = Uniforms.Executive, Auth = AuthLevel.ExecutiveAuth}
	}

Hello @Master1794

Im unsure about “.Activated” Try to use GuiButton.MouseButton1Up

Ex (Do that for every button)

Button[1].MouseButton1Up:Connect(function()
-- etc..Others code
1 Like

Well, first, replace Activated with MouseButton1Click.
…nevermind, didn’t read correctly.
Maybe instead of using tables, use dictionaries instead? (in some entries you’re combining both for whatever reason)
Third (optional), use task.wait instead of just wait.

if Character ~= nil then
    if Character:FindFirstChild('Shirt') then
        Character.Shirt.ShirtTemplate = 'templateLink'
    else
        local shirt = Instance.new('Shirt')
        shirt.ShirtTemplate = 'templateLink'
        shirt.Parent = Character
    end

    if Character:FindFirstChild('Pants') then
        Character.Pants.PantsTemplate= 'templateLink'
    else
        local pant = Instance.new('Pants')
        pant.PantsTemplate= 'templateLink'
        pant.Parent = Character
    end
end
Button.MouseButton1Click:Connect(function()

end)

@Sonostrano20

The idea of the loop was to try prevent repeating of code so if there’s a way to keep the loop then that’d be great.

Edit 2:
Right, I’ve gotten the buttons to work with the loop, GUI was set for the GUI in StarterGUI not PlayerGUI

@Inf_idel

I’ve tried this but it keep failing to change the clothing, I’ve tried things like http://www.roblox.com/asset/?id="..Uniform.Top but they still fail. If I go to the character in studio workspace when testing, I can click enter on the shirt template link and it works so idk what’s going on there.

Thanks for all the help, I’ve put an overall summary of the fix.

  • Combining the IDs with a number won’t work, set the Uniform.Top or Uniform.Bottoms value a string of the template link
  • PlayerGUI contains all the local GUI elements so must be used to detect the clicks.