Pants
*Ce contenu est traduit en utilisant l'IA (Beta) et peut contenir des erreurs. Pour consulter cette page en anglais, clique ici.
L'objet Pants affiche une texture de pantalon de Roblox sur une Humanoid plateforme.Les pantalons couvrent le torse et les jambes, et seront couverts par un Shirt sur le torse.Pour être visible, un Pants doit être le frère d'un Humanoid et avoir sa propriété PantsTemplate définie sur une texture appropriée telle que rbxassetid://86896501.La texture des pantalons peut être colorée en utilisant la propriété Clothing.Color3.
Les pantalons sont automatiquement chargés sur Player les caractères s'ils portent un avatar.
Échantillons de code
This sample includes a simple function to change the texture of the Shirt and Pants worn by a player's character. If shirt and pants don't exist then they are created. Note, this should be run every time the character spawns. If a developer is looking to permanently change a character's appearance to a preset it is recommended they use Player.CharacterAppearance.
local Players = game:GetService("Players")
local function replaceClothes(player)
local character = player.Character
if character then
-- look for shirts / pants
local shirt = character:FindFirstChildOfClass("Shirt")
local pants = character:FindFirstChildOfClass("Pants")
-- create shirts / pants if they don't exist
if not shirt then
shirt = Instance.new("Shirt")
shirt.Parent = character
end
if not pants then
pants = Instance.new("Pants")
pants.Parent = character
end
-- reset shirt / pants content ids
shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=83326831"
pants.PantsTemplate = "http://www.roblox.com/asset/?id=10045638"
end
end
for _index, player in ipairs(Players:GetPlayers()) do
replaceClothes(player)
end
Résumé
Propriétés
PantsTemplate
Le lien d'ID de contenu pointant vers le modèle de pantalon hébergé sur Roblox.
Cet ID de contenu est différent de l'URL du site Web des pantalons.Il peut être trouvé en collant l'URL du site Web des pantalons dans la propriété modèle de pantalon dans Studio.Alternativement, InsertService:LoadAsset() peut être utilisé pour insérer le pantalon dans l'espace de travail, par exemple :
local InsertService = game:GetService("InsertService")
local Workspace = game:GetService("Workspace")
local webURL = "https://www.roblox.com/catalog/1804739/Jeans"
local assetId = tonumber(string.match(webURL, "%d+") or 0) -- Extract the number
local success, model = pcall(function()
return InsertService:LoadAsset(assetId)
end)
if success then
model.Parent = Workspace
end
Pour le modèle d'un objet Shirt, voir Shirt.ShirtTemplate.
Échantillons de code
This sample includes a simple function to change the texture of the Shirt and Pants worn by a player's character. If shirt and pants don't exist then they are created. Note, this should be run every time the character spawns. If a developer is looking to permanently change a character's appearance to a preset it is recommended they use Player.CharacterAppearance.
local Players = game:GetService("Players")
local function replaceClothes(player)
local character = player.Character
if character then
-- look for shirts / pants
local shirt = character:FindFirstChildOfClass("Shirt")
local pants = character:FindFirstChildOfClass("Pants")
-- create shirts / pants if they don't exist
if not shirt then
shirt = Instance.new("Shirt")
shirt.Parent = character
end
if not pants then
pants = Instance.new("Pants")
pants.Parent = character
end
-- reset shirt / pants content ids
shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=83326831"
pants.PantsTemplate = "http://www.roblox.com/asset/?id=10045638"
end
end
for _index, player in ipairs(Players:GetPlayers()) do
replaceClothes(player)
end