Make a uniform equip toggle button UI

  1. What do you want to achieve? I would like to achieve, when pressing a button GUI you equip a shirt and pants, and if the user wants to unequip them, they should press again the same button and it will automatically unequip them, and so on.

  2. What is the issue? I can’t make it work, I tried so far and I only achieved to equip the clothes but not to unequip them or equip them back again all the times the user wants.

  3. What solutions have you tried so far? I looked for youtube tutorials and on roblox devforum but I haven’t found anything that could be useful for the GUI I’m trying to do.

I tried that

local button = script.Parent.GiveUniform
local debounce = true
local UniEventGC = game.ReplicatedStorage:WaitForChild("UniformGiveEvent")

button.MouseButton1Click:Connect(function()
	if debounce then
		debounce = false
		UniEvent:FireServer()
	end
end)
local Event = Instance.new("RemoteEvent")
Event.Parent = game.ReplicatedStorage
Event.Name = "UniformGiveEvent"
local Shirt = "rbxassetid://0"
local Pants = "rbxassetid://0"

function GiveUni(plr)
	local character = plr.Character
	local shirt = character.Shirt
	local pants = character.Pants
	shirt.ShirtTemplate = Shirt
	pants.PantsTemplate = Pants
end

Event.OnServerEvent:Connect(GiveUni)

I know that the shirt and pants ID are 0 I made that on purpose.

That’s what I tried so far but doesn’t work, only works one time and that is, and if you press again the uniform doesn’t unequip.

If anyone is willing to help me, I would really appreciate it. :slight_smile:

7 Likes

Just check if the player already has uniform on the server before giving it to them, and if they do, remove it, but if they don’t, then equip it.

function GiveUni(plr)
        if plr.Character.Shirt.ShirtTemplate == Shirt then
                  plr.Character.Shirt.ShirtTemplate = original shirt
                  plr.Character.Pants.PantsTemplate = original pants
                  return
        end
	local character = plr.Character
	local shirt = character.Shirt
	local pants = character.Pants
	shirt.ShirtTemplate = Shirt
	pants.PantsTemplate = Pants
end
8 Likes

I think you misspelt the variable name.

5 Likes

Also it works only once because you set the debounce variable to false, but never to true again, so the script just doesn’t fire the event.

6 Likes

I am getting an error
screenshot

2 Likes

Oh yeah, didn’t notice that, I already edited that.

2 Likes

Consider removing spaces and defining the variables

2 Likes

Ok, now the uniform giver works great, now, how I do when you click again the button it returns to your original clothes

1 Like

By the way thx for helping me I’m not a lot into scripting and you guys are helping me a lot

There should be character’s original shirt and pants. You can get them using game.Players:GetHumanoidDescriptionFromUserId(plr.UserId).Shirt
and
game.Players:GetHumanoidDescriptionFromUserId(plr.UserId).Pants

1 Like

And then applying them to the humanoid
(via applydescription)

1 Like

Just paste this instead of your own function, it should work perfectly fine:

function GiveUni(plr)
        if plr.Character.Shirt.ShirtTemplate == Shirt then
                  plr.Character:WaitForChild("Humanoid"):ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(plr.UserId))
                  return
        end
	local character = plr.Character
	local shirt = character.Shirt
	local pants = character.Pants
	shirt.ShirtTemplate = Shirt
	pants.PantsTemplate = Pants
end
2 Likes

Don’t need to reload all the accessories, since it’s not really smooth. They just need to change the shirt and pants.

2 Likes

Ok, I used the script you sent and it worked, but the problem is that it don’t give the clothes I had, just removes all the clothes, how I can fix that?

I made a video so you can see what I meant

1 Like

Save the origonal clothing in the script and re equip thoes cloths instead of taking them off

2 Likes

My bad, try again, I updated my script

2 Likes

But then if player will change avatar in the middle of the game, script will keep their old shirt and pants

2 Likes

Is what i wrote not going to work? Your message confused me

2 Likes

It’s fine!

This is what does now.

1 Like

I could have misspelt something, try again, it must work (I updated the script once again and hopped on studio to see if it’s working and it does)

2 Likes