Advertisement
Guest User

Roblox Gamepass Script

a guest
Nov 7th, 2016
25,965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. --------------------
  2. --| WaitForChild |--
  3. --------------------
  4.  
  5. -- Waits for parent.child to exist, then returns it
  6. local function WaitForChild(parent, childName)
  7. assert(parent, "ERROR: WaitForChild: parent is nil")
  8. while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
  9. return parent[childName]
  10. end
  11.  
  12. -----------------
  13. --| Variables |--
  14. -----------------
  15.  
  16. local GamePassService = Game:GetService('GamePassService')
  17. local PlayersService = Game:GetService('Players')
  18. local InsertService = Game:GetService('InsertService')
  19. local LightingService = Game:GetService('Lighting') --TODO: Use new data store service once that exists
  20.  
  21. local GamePassIdObject = WaitForChild(script, 'GamePassId')
  22. local ToolAssetsToLoad = WaitForChild(script, 'ToolAssetsToLoad')
  23.  
  24. local AdminTools = LightingService:FindFirstChild('AdminTools')
  25.  
  26. -----------------
  27. --| Functions |--
  28. -----------------
  29.  
  30. -- Makes copies of all the admin tools and puts them in target
  31. local function CloneAdminTools(target)
  32. for _, tool in pairs(AdminTools:GetChildren()) do
  33. local toolClone = tool:Clone()
  34. toolClone.Parent = target
  35. end
  36. end
  37.  
  38. -- When a player with the game pass joins, give them the admin tools
  39. local function OnPlayerAdded(player)
  40. if GamePassService:PlayerHasPass(player, GamePassIdObject.Value) then
  41. local starterGear = WaitForChild(player, 'StarterGear')
  42. CloneAdminTools(starterGear)
  43. if player.Character then -- They've already loaded and won't get their StarterGear until next spawn
  44. local backpack = WaitForChild(player, 'Backpack')
  45. CloneAdminTools(backpack)
  46. end
  47. end
  48. end
  49.  
  50. --------------------
  51. --| Script Logic |--
  52. --------------------
  53.  
  54. -- Create AdminTools if it doesn't exist
  55. if not AdminTools then
  56. AdminTools = Instance.new('Model')
  57. AdminTools.Name = 'AdminTools'
  58.  
  59. -- Load all of the assets in ToolAssetsToLoad and put them in AdminTools
  60. for _, intObject in pairs(ToolAssetsToLoad:GetChildren()) do
  61. if intObject and intObject:IsA('IntValue') and intObject.Value then
  62. local assetModel = InsertService:LoadAsset(intObject.Value)
  63. if assetModel then
  64. local asset = assetModel:GetChildren()[1]
  65. if asset then
  66. asset.Parent = AdminTools
  67. end
  68. end
  69. end
  70. end
  71.  
  72. AdminTools.Parent = LightingService
  73. end
  74.  
  75. PlayersService.PlayerAdded:connect(OnPlayerAdded)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement