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

oh my god did I even do this correctly??

Asked by
Xuvia 0
5 years ago
local gamepass = script:WaitForChild("GamePassId")
local service = game:GetService("GamePassService")

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)

OK, so something weird happened, when I exited studio then came back to this, the unknown global error was gone. But when I test it out, I don't get what I should for the gamepass. So far it's been a big trial and error for me lol. And the whole script is just named Script, has an IntValue attached to it. Yeah, I'm a newbie at scripting sorry.

0
Soooo... what is the issue you're having? climethestair 1663 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

The PlayerHasPass method was broken in the April game pass update, where game passes were no longer asset IDs. You'll need to use Marketplace:UserOwnsGamePassAsync().

local gamepass = script:WaitForChild("GamePassId")
local service = game:GetService("GamePassService")
local gamepass = script:WaitForChild("GamePassId")
local service = game:GetService("MarketplaceService")

game:GetService("Players").PlayerAdded:Connect(function(player) -- uppercase C
    if service:UserOwnsGamePassAsync(player.UserId,gamepass.Value) then
        local tools = game:GetService:WaitForChild("Tools") 

        for i,v in pairs(tools:GetChildren()) do -- uppercase G
            if v:IsA("BackpackItem") then -- IsA not isA
                v:Clone().Parent = player:WaitForChild("Backpack")
                v:Clone().Parent = player:WaitForChild("StarterGear")
            end
        end
     end
end)

On a side note, :connect(), :getChildren(), :isA() are deprecated, make the first letter of each word an uppercase instead.

Ad

Answer this question