Advertisement
Sungmingamerpro13

DataStore Shirt and Pants

Aug 17th, 2023
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 2.28 KB | None | 0 0
  1. local DataStoreService = game:GetService("DataStoreService")
  2. local PlayerDataStore = DataStoreService:GetDataStore("PlayerDataStore")
  3.  
  4. -- IDs de las texturas predeterminadas en el catálogo de Roblox
  5. local DefaultShirtTextureID = -- ID de la textura de la camiseta predeterminada
  6. local DefaultPantsTextureID = -- ID de la textura de los pantalones predeterminados
  7.  
  8. game.Players.PlayerAdded:Connect(function(player)
  9.     local userId = tostring(player.UserId)
  10.    
  11.     -- Intentar cargar las texturas guardadas del jugador
  12.     local success, savedTextures = pcall(function()
  13.         return PlayerDataStore:GetAsync(userId)
  14.     end)
  15.    
  16.     local character = player.Character
  17.     if character then
  18.         character:ClearAllChildren()
  19.         character.HumanoidRootPart.Anchored = true
  20.        
  21.         local humanoid = character:FindFirstChild("Humanoid")
  22.         humanoid:RemoveAccessories() -- Quitar accesorios existentes
  23.        
  24.         local shirt = Instance.new("Shirt")
  25.         local pants = Instance.new("Pants")
  26.        
  27.         if success and savedTextures then
  28.             shirt.ShirtTemplate = savedTextures.ShirtTemplate or DefaultShirtTextureID
  29.             pants.PantsTemplate = savedTextures.PantsTemplate or DefaultPantsTextureID
  30.         else
  31.             shirt.ShirtTemplate = DefaultShirtTextureID
  32.             pants.PantsTemplate = DefaultPantsTextureID
  33.         end
  34.        
  35.         shirt.Parent = character
  36.         pants.Parent = character
  37.        
  38.         humanoid:BuildRigFromAttachments() -- Reconstruir el esqueleto
  39.         character.HumanoidRootPart.Anchored = false
  40.     end
  41. end)
  42.  
  43. game.Players.PlayerRemoving:Connect(function(player)
  44.     local userId = tostring(player.UserId)
  45.     local character = player.Character
  46.    
  47.     if character then
  48.         local shirtTemplate = character:FindFirstChild("Shirt"):GetAttribute("ShirtTemplate")
  49.         local pantsTemplate = character:FindFirstChild("Pants"):GetAttribute("PantsTemplate")
  50.        
  51.         local texturesData = {
  52.             ShirtTemplate = shirtTemplate,
  53.             PantsTemplate = pantsTemplate
  54.         }
  55.        
  56.         -- Guardar las texturas actuales del jugador en el DataStore
  57.         pcall(function()
  58.             PlayerDataStore:SetAsync(userId, texturesData)
  59.         end)
  60.     end
  61. end)
  62.  
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement