Uniform Equiper

I own a hotel group, and have recently had uniforms made. I have seen in other hotels when the user walks into the reception area they are instantly given uniform. How could I do this?

Thanks,
George.

3 Likes

Add a part covering the entire entrance. Then, add a script to the part. The script will use .Touched to get the touching parts, and use the shirt and pants object of the character to make them wear the uniform. Sort of like this:

local door = script.Parent
local shirtId = 123456 --Id of the shirt here
local pantsId = 123456 --Id of the pants here

function onHit(part)
    --Check if the part is part of a character:
    if part.Parent:FindFirstChild("Humanoid") == nil then
        return
    end

   part.Parent.Shirt.ShirtTemplate = shirtId --Change the shirt
   part.Parent.Pants.PantsTemplate = pantsId --Change the pants
end

door.Touched:Connect(onHit)

That should work.

I haven’t tested this yet, please tell me if there is an error. :smile:

3 Likes

You need to make sure the player is wearing a shirt and pants in the first place though…

If not, make it create the instances inside the player’s character.

2 Likes

To be honest if one of the staff is not wearing a clothes in my hotel I will likely remove them anyway aha.

3 Likes

Oops, didn’t realize that. Here is the hopefully working code:

local door = script.Parent
local shirtId = 123456 --Id of the shirt here
local pantsId = 123456 --Id of the pants here

function onHit(part)
    --Check if the part is part of a character:
    if part.Parent:FindFirstChild("Humanoid") == nil then
        return
    end
  
    if part.Parent:FindFirstChild("Shirt") then
        part.Parent.Shirt.ShirtTemplate = shirtId --Changes the shirt
    else
        local shirt = Instance.new("Shirt", part.Parent)
        shirt.ShirtTemplate = shirtId --Changes the shirt
    end
   
    if part.Parent:FindFirstChild("Pants") then
        part.Parent.Pants.PantsTemplate = pantsId --Changes the pants
    else
        local pants = Instance.new("Pants", part.Parent)
        pants.PantsId = pantsId --Changes the Pants
    end
   
door.Touched:Connect(onHit)

BTW, don’t forget to make the part covering the door Transparent and set CanCollide to False.

3 Likes

Nothing happened. :frowning:

https://www.roblox.com/games/4867149664/The-Manor-Spa-and-Resort-WIP-Not-scripted?refPageId=99ab3141-60dc-4429-ab28-b82c9cca0c7b#

1 Like

Did you replace the 123456 with the correct shirtId and pantsId? Also, were there any errors?

Yes, I did. I will check now for errors. No errors.

I believe you should insert a Script INTO a part in Workspace. Also add a “Pants” and “Shirt” object into the part. The ID for the shirts should be in the properties of the “Shirt” and “Pants”

function onTouched(part)

	local h = part.Parent:findFirstChild("Humanoid")
	if h~=nil then

	local pants = part.Parent:FindFirstChild("Pants")
	local top = part.Parent:FindFirstChild("Shirt")
	

	if top ~= nil then 
	top:remove()
		if pants ~= nil then 
		pants:remove()
		newpants = script.Parent.Pants:clone()
		newpants.Parent = part.Parent

		newshirt = script.Parent.Shirt:clone()
		newshirt.Parent = part.Parent

		else
		newpants = script.Parent.Pants:clone()
		newpants.Parent = part.Parent

		newshirt = script.Parent.Shirt:clone()
		newshirt.Parent = part.Parent
		end

	elseif pants ~= nil then 
	pants:remove()
	newpants = script.Parent.Pants:clone()
	newpants.Parent = part.Parent

	newshirt = script.Parent.Shirt:clone()
	newshirt.Parent = part.Parent
	else

	newpants = script.Parent.Pants:clone()
	newpants.Parent = part.Parent

	newshirt = script.Parent.Shirt:clone()
	newshirt.Parent = part.Parent

	end




	end
end



script.Parent.Touched:connect(onTouched)```
2 Likes

Okay. I’m busy right now, so I will have to check this out later. Sorry that I couldn’t help right now.

BTW, Instance:Remove() was deprecated. It’s Instance:Destroy() now.

Finally got it to work!!

Note: I made the part the player walks through visible for presentation purposes
You can get it here:

How to use
Inside of the part, you will see a shirt and pants. Change the ShirtId and PantsId of shirts and pants to the id you would like to use.
Screen Shot 2020-04-15 at 4.40.42 PM
Once you did that, it should work!

This entire thing is open-sourced, the code is here:

local door = script.Parent

local shirtId = script.Parent.Shirt
local pantsId = script.Parent.Pants

local shirt = nil
local pants = nil

local givenPlayers = {}

function touched(part)
	if part.Parent:FindFirstChild("Humanoid") == nil then
		return
	end
	
	if #givenPlayers ~= 0 then
		for index = 1, #givenPlayers do
			if givenPlayers[index] == part.Parent.Name then
				return
			end
		end
	end
	
	shirt = part.Parent:FindFirstChildOfClass("Shirt")
	if shirt ~= nil then
		shirt:Destroy()
	end
	
	shirt = script.Parent.Shirt:Clone()
	shirt.Parent = part.Parent
	
	pants = part.Parent:FindFirstChildOfClass("Pants")
	if pants ~= nil then
		pants:Destroy()
	end
	
	pants = script.Parent.Pants:Clone()
	pants.Parent = part.Parent
	
	print("Gave uniform to " .. tostring(part.Parent.Name) .. "!")
	
	givenPlayers[#givenPlayers + 1] = part.Parent.Name
end

door.Touched:Connect(touched)
5 Likes