HowToRoblox

LoadoutHandler

Apr 21st, 2021
898
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local weaponsFolder = game.ReplicatedStorage:WaitForChild("Weapons")
  2. local weaponTypes = {weaponsFolder.Primary, weaponsFolder.Secondary, weaponsFolder.Melee}
  3.  
  4.  
  5. local loadout = script.Parent:WaitForChild("Loadout")
  6. loadout.Visible = false
  7.  
  8.  
  9. local primary = nil
  10. local secondary = nil
  11. local melee = nil
  12.  
  13.  
  14. local function updateLoadout()
  15.    
  16.     loadout.WeaponsEquipped.Text = ""
  17.    
  18.     if primary then
  19.         loadout.WeaponsEquipped.Text = "Primary: " .. primary.Name
  20.         game.ReplicatedStorage.EquipWeaponRE:FireServer(primary)
  21.     end
  22.    
  23.     if secondary then
  24.         loadout.WeaponsEquipped.Text = loadout.WeaponsEquipped.Text .. "\nSecondary: " .. secondary.Name
  25.         game.ReplicatedStorage.EquipWeaponRE:FireServer(secondary)
  26.     end
  27.    
  28.     if melee then
  29.         loadout.WeaponsEquipped.Text = loadout.WeaponsEquipped.Text .. "\nMelee: " .. melee.Name
  30.         game.ReplicatedStorage.EquipWeaponRE:FireServer(melee)
  31.     end
  32. end
  33. updateLoadout()
  34.  
  35.  
  36. for i, weaponType in pairs(weaponTypes) do
  37.    
  38.     local newButton = script.WeaponTypeButton:Clone()
  39.     newButton.Text = weaponType.Name
  40.    
  41.     newButton.Parent = loadout.WeaponTypes
  42.    
  43.    
  44.     newButton.MouseButton1Click:Connect(function()
  45.        
  46.         for i, child in pairs(loadout.WeaponsList:GetChildren()) do
  47.            
  48.             if child:IsA("TextButton") then child:Destroy() end
  49.         end
  50.        
  51.        
  52.         for i, weaponChild in pairs(weaponType:GetChildren()) do
  53.            
  54.             local newWeaponButton = script.WeaponButton:Clone()
  55.             newWeaponButton.Text = weaponChild.Name
  56.            
  57.             newWeaponButton.Parent = loadout.WeaponsList
  58.            
  59.            
  60.             newWeaponButton.MouseButton1Click:Connect(function()
  61.                
  62.                 if weaponType.Name == "Primary" then
  63.                     primary = weaponChild
  64.                    
  65.                 elseif weaponType.Name == "Secondary" then
  66.                     secondary = weaponChild
  67.                    
  68.                 elseif weaponType.Name == "Melee" then
  69.                     melee = weaponChild
  70.                 end
  71.                
  72.                 updateLoadout()
  73.             end)
  74.         end
  75.     end)
  76. end
  77.  
  78.  
  79.  
  80. script.Parent:WaitForChild("ToggleLoadoutGui").MouseButton1Click:Connect(function()
  81.    
  82.     loadout.Visible = not loadout.Visible
  83. end)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×