Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script for my gamepass isn't working why and how can I make it correct?

Why is this not working? I have a folder called Tools in replicated storage. My gamepass script has a intvalue called GamePassId.


local gamepass = script:WaitForChild("GamePassId")
local service = game:GetService("GamePassService")
local tools = game.ReplicatedStorage:WaitForChild()

game.Players.PlayerAdded:connect(function(player) if service:PlayerHasPass(player,gamepass.Value)
 then local tools = game.ReplicatedStorage:WaitForChild("Tools")
 for i,v in pairs(tools:GetChildren()) do 
  if v:isA("Tool") then
   v:Clone().Parent = player:WaitForChild("Backpack")
   v:Clone().Parent = player:WaitForChild("StarterGear")
  end
 end
end
end)

1 answer

✓ Accepted answer

I'm sure you'll find a lot of answers on this already but you need to change your GamePassService. Below is an example of changing it to MarketplaceService.


local allow = (

       game:GetService('MarketplaceService'):UserOwnsGamePassAsync(player.userId, 1234567) -- GamePass id here

   )

And here's a similar script from a past post (not mine).

local GamePasses = {
--- {PassID, Cash Reward, Item Reward(s)};
    {127504583, 10000, {'Tool1','Tool2'}};                          -- Mini VIP
    {138347949, 500000, {}};                                        -- Mega VIP
}

local mpService,Players,rStorage = game:GetService('MarketplaceService'),game:GetService('Players'),game:GetService('ReplicatedStorage')
local ToolBin = rStorage:WaitForChild('Tools')

Players.PlayerAdded:connect(function(Player)
    local Cash = Player:WaitForChild('leaderstats'):WaitForChild('Cash')
    for _,GamePass in pairs(GamePasses) do
        if mpService:UserOwnsGamePassAsync(Player.UserId, GamePass[1]) then
            Cash.Value = Cash.Value + GamePass[2]
            for _,Tool in pairs(GamePass[3]) do
                local newTool = ToolBin:WaitForChild(Tool)
                newTool:Clone().Parent = Player:WaitForChild('Backpack')
                newTool:Clone().Parent = Player:WaitForChild('StarterGear')
            end
        end
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.