Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

In this script, how could I make the uniform changing process automatic?

Hello, I've recently got into scripting, and have started dissecting free model scripts to try and learn as much as I can. I would like to know what part of this script is responsible for the player having to press a button to equip the uniform, and what parts I'd need to remove to make the player equip the uniform on spawn.

The group, pants and shirt IDs are all stored as IntValues, and the script works thus far:

print("Loaded Uniform Script.")

repeat wait() until game.Players.LocalPlayer
local Player = game.Players.LocalPlayer
local Character = Player.Character

--Settings
local ScreenGui = script.Parent
local UniformButton = ScreenGui:WaitForChild("UniformButton")

local Settings = script.Parent:WaitForChild("Settings")
local CertainTeam = Settings:WaitForChild("CertainTeam")
local CertainTeamColour = CertainTeam:WaitForChild("TeamColor")

local UniformRanks = Settings:WaitForChild("UniformRanks")
local GroupId = Settings:WaitForChild("GroupId")

local Ranks = {}

--Functions
function GetSettings()
	if CertainTeam.Value then
		if Player.TeamColor ~= CertainTeamColour.Value then
			ScreenGui:Destroy()
		end
	end	
	
	for i, v in pairs(UniformRanks:GetChildren()) do
		if v:IsA("NumberValue") or v:IsA("IntValue") then
			if string.find(v.Name, "Rank") then --Checks it's called "Rank"
				table.insert(Ranks, string.sub(v.Name, 1, 5))
			end
		end
	end	
end

GetSettings()
local HighestRank = 0

UniformButton.MouseButton1Down:connect(function()
	if Player:IsInGroup(GroupId.Value) then
		if table.getn(Ranks) ~= 0 then --Checks that the table isn't empty.
			for i, v in pairs(Ranks) do
				local PlayerRank = Player:GetRankInGroup(GroupId.Value)
				local Rank = UniformRanks:FindFirstChild(v)
				
				if PlayerRank >= Rank.Value then
					if PlayerRank > HighestRank then
						--Gets the highest ranked uniform a player can wear.
						HighestRank = Rank.Value
					end
				end
			end
			
			if HighestRank ~= 0 then
				local Uniform = {}
				for i, v in pairs(UniformRanks:GetChildren()) do
					if v.Value == HighestRank then
						Uniform.Shirt = "http://www.roblox.com/asset/?id=" ..v:FindFirstChild("ShirtId").Value
						Uniform.Pants = "http://www.roblox.com/asset/?id=" ..v:FindFirstChild("PantsId").Value
					end
				end
				
				--Removes Shirt/Pants if they are wearing any.
				for i, Object in next, Character:GetChildren() do
					if Object:IsA("Shirt") or Object:IsA("Pants") then
						Object:Destroy()
					end
				end
				
				local Shirt = Instance.new("Shirt", Character)
				local Pants = Instance.new("Pants", Character)
			    Shirt.ShirtTemplate = Uniform.Shirt
			    Pants.PantsTemplate = Uniform.Pants
			--else
				--print(Player.Name, "tried to wear some uniform, but the ranks are too high for them!")
			end
		end
	end
end)

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.