So I have a segway in Server Storage that I want to do so if you buy it, you just need to rejoin the server to have it. Cause the gamepass script that I have now needs a server restart before it works. The gamepass Id is : 503854648
Thanks!
[UPDATE] -The script is in Workspace and there is a value in the script with the gamepass id. Thats the code that I have now :
--------------------
--| 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 ServerStorageService = game:GetService('ServerStorage') --TODO: Use new data store service once that exists
local GamePassIdObject = WaitForChild(script, 'GamePassId')
local AdminTools = WaitForChild(ServerStorageService, 'Seg')
-----------------
--| 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 |--
--------------------
PlayersService.PlayerAdded:connect(OnPlayerAdded)

1 comment
You don't need to rewrite the WaitForChild function. If you don't want to use the method syntax, just localize it by: local WaitForChild = game.WaitForChild