Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by
ABK2017 406 Moderation Voter
5 years ago
Edited 5 years ago

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)
Ad

Answer this question