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

Game Pass Not Working throwing a cast error how to fix?

Asked by 6 years ago
--------------------
--| 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 InsertService = Game:GetService('InsertService')
local LightingService = Game:GetService('Lighting') --TODO: Use new data store service once that exists

local GamePassIdObject = WaitForChild(script, 'GamePassId')
local ToolAssetsToLoad = WaitForChild(script, 'ToolAssetsToLoad')

local AdminTools = LightingService:FindFirstChild('AdminTools')

-----------------
--| 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)
    print("Works!")
    if game.GamePassService:PlayerHasPass(player, 4504171) then
        print("Gamepass!")
        local starterGear = WaitForChild(player, 'StarterGear')
        CloneAdminTools(starterGear)
    else 
        print("NoGPass")

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

-- Create AdminTools if it doesn't exist
if not AdminTools then
    AdminTools = Instance.new('Model')
    AdminTools.Name = 'AdminTools'

    -- Load all of the assets in ToolAssetsToLoad and put them in AdminTools
    for _, intObject in pairs(ToolAssetsToLoad:GetChildren()) do
        if intObject and intObject:IsA('IntValue') and intObject.Value then
            local assetModel = InsertService:LoadAsset(intObject.Value)
            if assetModel then
                local asset = assetModel:GetChildren()[1]
                if asset then
                    asset.Parent = AdminTools
                end
            end
        end
    end

    AdminTools.Parent = LightingService
end

PlayersService.PlayerAdded:connect(OnPlayerAdded)

It keeps throwing an error saying that Internal Server error, cannot cast instance into int64

0
On what line? MooMooThalahlah 421 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
   --if game.GamePassService:PlayerHasPass(player, 1768311517) then GPService sucks
   if game.MarketplaceService:PlayerOwnsAsset(player, 1768311517) then --one of the benefits is you can call MPService from a LocalScript wheras you can't with GPService
        print("Gamepass!")
        local starterGear = WaitForChild(player, 'StarterGear')
        CloneAdminTools(starterGear)
    else 
        print("NoGPass")

        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

https://wiki.roblox.com/index.php?title=API:Class/MarketplaceService/PlayerOwnsAsset

0
Except PlayerOwnsAsset checks if the player owns the asset with that id, not the gamepass. And the asset belonging to the id 4504171 is someone's place. Meaning it would always return false. Amiaa16 3227 — 6y
0
Btw the assetid of that gamepass is 1768311517 Amiaa16 3227 — 6y
0
Hm, always worked for me. Well updated now. SebbyTheGODKid 198 — 6y
Ad

Answer this question