How to check if a player is wearing the correct clothing?

Hello
I tried to make a script that checks if the player has certain shirts/pants from a table and if they don’t it replaces it.
It seems like checking the tables must be the issue but I’m not sure how to fix it.
Currently it gives me the replaced outfit.
Here is the script

Shirts = {
	"rbxassetid://9041476683",
	"rbxassetid://9010875944",
	"rbxassetid://9010870140",
	"rbxassetid://10197365215",
	"rbxassetid://9776861651",
	"rbxassetid://9513082336",
	"rbxassetid://10207652784",
	"rbxassetid://9710458504"
} -- Shirt IDs

Pants = {
	"rbxassetid://9010873129",
	"rbxassetid://10197383329",
	"rbxassetid://9776863373",
	"rbxassetid://9513084493",
	"rbxassetid://10207658360",
	"rbxassetid://9710460441"
} -- Pants IDs

--[Uniform Whitelister]
game.Players.PlayerAdded:Connect(function(plar)
	plar.CharacterAppearanceLoaded:Connect(function(char)
		wait()
		if plar.Team == team["Templars"] then
			if char.Shirt.ShirtTemplate == Shirts[char.Shirt.ShirtTemplate] and char.Pants.PantsTemplate == Pants[char.Pants.PantsTemplate] then
				print("Correct Uniform")
			else
				print("Incorrect Uniform")
				char.Shirt.ShirtTemplate = "rbxassetid://125195175" -- Default Shirt
				char.Pants.PantsTemplate = "rbxassetid://125195171" -- Default Pants
			end
		end
	end)
end)

I’m not very sure how I’m supposed to fix this

You have to use table.find:

--//Services
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

--//Tables
local Shirts = {
	"rbxassetid://9041476683",
	"rbxassetid://9010875944",
	"rbxassetid://9010870140",
	"rbxassetid://10197365215",
	"rbxassetid://9776861651",
	"rbxassetid://9513082336",
	"rbxassetid://10207652784",
	"rbxassetid://9710458504"
} -- Shirt IDs

local Pants = {
	"rbxassetid://9010873129",
	"rbxassetid://10197383329",
	"rbxassetid://9776863373",
	"rbxassetid://9513084493",
	"rbxassetid://10207658360",
	"rbxassetid://9710460441"
} -- Pants IDs

--[Uniform Whitelister]

--//Functions
Players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(character)
		task.wait()
		
		if player.Team == Teams.Templars then
			if table.find(Shirts, character.Shirt.ShirtTemplate) and table.find(Pants, character.Pants.PantsTemplate) then
				print("Correct uniform")
			else
				print("Incorrect Uniform")
				character.Shirt.ShirtTemplate = "rbxassetid://125195175" -- Default Shirt
				character.Pants.PantsTemplate = "rbxassetid://125195171" -- Default Pants
			end
		end 
	end)
end)
3 Likes

Tried this and nothing changed
Im trying to make it so if you are wearing a shirt and pants that are in the table then you can wear them otherwise it replaces them

1 Like

If you type in

print(character.Shirt.ShirtTemplate) 

It returns something like this:

http://www.roblox.com/asset/?id=9513084493

So I think what you would need to do is update “rbxassetid://” to “http://www.roblox.com/asset/?id=
Hopefully this works! :slight_smile:

Hmm
Doesn’t seem to do anything

Is your script in ServerScriptService? It seems to work for me

1 Like

image

--//Services
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

--//Tables
local Shirts = {
	"http://www.roblox.com/asset/?id=9041476683",
	"http://www.roblox.com/asset/?id=9010875944",
	"http://www.roblox.com/asset/?id=9010870140",
	"http://www.roblox.com/asset/?id=10197365215",
	"http://www.roblox.com/asset/?id=9776861651",
	"http://www.roblox.com/asset/?id=9513082336",
	"http://www.roblox.com/asset/?id=10207652784",
	"http://www.roblox.com/asset/?id=9710458504"
} -- Shirt IDs

local Pants = {
	"http://www.roblox.com/asset/?id=9010873129",
	"http://www.roblox.com/asset/?id=10197383329",
	"http://www.roblox.com/asset/?id=9776863373",
	"http://www.roblox.com/asset/?id=9513084493",
	"http://www.roblox.com/asset/?id=10207658360",
	"http://www.roblox.com/asset/?id=9710460441"
} -- Pants IDs

--[Uniform Whitelister]

--//Functions
Players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(character)
		task.wait()

		if player.Team == Teams.Templars then
			if table.find(Shirts, character.Shirt.ShirtTemplate) and table.find(Pants, character.Pants.PantsTemplate) then
				print("Correct uniform")
			else
				print("Incorrect Uniform")
				character.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=125195175" -- Default Shirt
				character.Pants.PantsTemplate = "http://www.roblox.com/asset/?id=125195171" -- Default Pants
			end
		end 
	end)
end)

Try pasting this into “UniformWhitelist”

This is what I see:
image
image

Add your IDs to the tables and see if it still changes your outfit

Oh i see the issue,

print(character.Shirt.ShirtTemplate)

returns the shirt template id not the catalog id of the shirt… so you would need to update those ids to the shirt templates

There is probably an easier way to do it as of now im not quite sure

Is there an easier way?
Maybe changing something in the script?

I hope this helps

It doesn’t print “Correct Uniform” and doesnt change it if it’s wrong
Im so confused

This is what he means: Try and put one of the IDs in a shirt in Roblox Studio, it should change.

That should bring you to the template, you will need to use that link to change their shirt not the ID for the actual shirt itself. It should look identical to the shirts in your shirt table just different IDs for each

It should look like: “rbxassetid://123”, 123 being the ID

(Also dont mind what I said in the edits, I seen it in another post and didnt test it out, it doesnt work)

local Game = game
local Players = Game:GetService("Players")

local ShirtIds = {0, 1, 2, 3} --Enter whitelisted shirt IDs here.
local PantsIds = {0, 1, 2, 3} --Enter whitelisted pants IDs here.
local DefaultShirtId = 0 --ID of default shirt.
local DefaultPantsId = 0 --ID of default pants.

local function OnPlayerAdded(Player)
	local function OnCharacterAdded(Character)
		if not Player:HasAppearanceLoaded() then Player.CharacterAppearanceLoaded:Wait() end
		
		local Shirt = Character:FindFirstChildOfClass("Shirt")
		if Shirt then
			local ShirtId = string.match(Shirt.ShirtTemplate, "%d+$")
			ShirtId = tonumber(ShirtId)
			if not table.find(ShirtIds, ShirtId) then Shirt.ShirtTemplate = "rbxassetid://"..DefaultShirtId end
		else
			Shirt = Instance.new("Shirt")
			Shirt.ShirtTemplate = "rbxassetid://"..DefaultShirtId
			Shirt.Parent = Character
		end
		
		local Pants = Character:FindFirstChildOfClass("Pants")
		if Pants then
			local PantsId = string.match(Pants.PantsTemplate, "%d+$")
			PantsId = tonumber(PantsId)
			if not table.find(PantsIds, PantsId) then Pants.PantsTemplate = "rbxassetid://"..DefaultPantsId end
		else
			Pants = Instance.new("Pants")
			Pants.PantsTemplate = "rbxassetid://"..DefaultPantsId
			Pants.Parent = Character
		end
	end
	
	Player.CharacterAdded:Connect(OnCharacterAdded)
end

Players.PlayerAdded:Connect(OnPlayerAdded)

Here’s a generic template script you can use.