generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Is there a way to fix this?

Previous Thread :: Next Thread 
Ethix is not online. Ethix
Joined: 23 Nov 2008
Total Posts: 8506
30 Jul 2014 11:38 AM
I want to be able to sell gear as gamepasses. This script works, but is the user buys it in game they do not get the gear until they rejoin. Is there a way to make this script give the player the tool on next respawn?

This script is universal for all the gamepasses not for just a certain model, by the way.






--------------------
--| WaitForChild |--
--------------------

-- Waits for parent.child to exist, then returns it
local function WaitForChild(parent, childName)
assert(parent, "ERROR: WaitForChild: parent is nil")
while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
return parent[childName]
end

-----------------
--| Variables |--
-----------------

local GamePassService = Game:GetService('GamePassService')
local PlayersService = Game:GetService('Players')
local InsertService = Game:GetService('InsertService')
local LightingService = Game:GetService('Lighting') --TODO: Use new data store service once that exists

local GamePassIdObject = WaitForChild(script, 'GamePassId')
local ToolAssetsToLoad = WaitForChild(script, 'ToolAssetsToLoad')

local AdminTools = LightingService:FindFirstChild('AdminTools')

-----------------
--| Functions |--
-----------------

-- Makes copies of all the admin tools and puts them in target
local function CloneAdminTools(target)
for _, tool in pairs(AdminTools:GetChildren()) do
local toolClone = tool:Clone()
toolClone.Parent = target
end
end

-- When a player with the game pass joins, give them the admin tools
local function OnPlayerAdded(player)
if GamePassService:PlayerHasPass(player, GamePassIdObject.Value) then
local starterGear = WaitForChild(player, 'StarterGear')
CloneAdminTools(starterGear)
if player.Character then -- They've already loaded and won't get their StarterGear until next spawn
local backpack = WaitForChild(player, 'Backpack')
CloneAdminTools(backpack)
end
end
end

--------------------
--| Script Logic |--
--------------------

-- Create AdminTools if it doesn't exist
if not AdminTools then
AdminTools = Instance.new('Model')
AdminTools.Name = 'AdminTools'

-- Load all of the assets in ToolAssetsToLoad and put them in AdminTools
for _, intObject in pairs(ToolAssetsToLoad:GetChildren()) do
if intObject and intObject:IsA('IntValue') and intObject.Value then
local assetModel = InsertService:LoadAsset(intObject.Value)
if assetModel then
local asset = assetModel:GetChildren()[1]
if asset then
asset.Parent = AdminTools
end
end
end
end

AdminTools.Parent = LightingService
end

PlayersService.PlayerAdded:connect(OnPlayerAdded)
Report Abuse
Ethix is not online. Ethix
Joined: 23 Nov 2008
Total Posts: 8506
30 Jul 2014 11:46 AM
Thanks!
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
30 Jul 2014 11:54 AM
Just give the player the weapon or whatever directly. When they relog they will get the item again.
Report Abuse
Ethix is not online. Ethix
Joined: 23 Nov 2008
Total Posts: 8506
30 Jul 2014 12:36 PM
How can i do that?
Report Abuse
Ethix is not online. Ethix
Joined: 23 Nov 2008
Total Posts: 8506
30 Jul 2014 12:37 PM
o.o
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image