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)
Hey,
The problem is the PlayerAdded event. You're only checking it once. What I would do is when the player joins, run a loop (every 15 seconds) and call the function "OnPlayerAdded" with the player's name of course. So, in the end:
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 return true end end game.Players.PlayerAdded:connect(function(p) while wait(15) do if OnPlayerAdded(p) then break end end end)
Another way you can do is make a gui that when clicked, checks if the player has the gamepass or not (you should set a time frame between each "check" so the players wont spam the button).