#1 error making a gamepass team only script

33 messages · Page 1 of 1 (latest)

sacred holly
#

ive been working on a scp game, making the teams, i needed to script the gamepass teams, so what this script is supossed to do is letting a player join the specified team if he has a specified gamepass, if not, it prompt them to buy it, the problem is that when i try joining the team i get this error " Unable to cast value to Object - Client - LocalScript:17", this is for a button ui, im new to scripting, can you help me solving the problem please? (there are some notes i made in the script)

-- Replace this with the ID of the gamepass you want to check for
local gamepassId = 164110210

-- Replace this with the name of the team you want players to join
local teamName = "05 Council"

-- Wait for the player to fully load into the game
repeat wait() until game.Players.LocalPlayer

-- Get the player's ID
local playerId = game.Players.LocalPlayer.UserId

-- Find the team with the specified name
local team = game.Teams:FindFirstChild(teamName)
if team then
    -- Check if the player has the gamepass
    if game:GetService("GamePassService"):PlayerHasPass(playerId, gamepassId) then
        -- The player has the gamepass, so let them join the team
        game.Players.LocalPlayer.Team = team
    else
        -- The player doesn't have the gamepass, so prompt them to buy it
        local gamepassInfo = game:GetService("MarketplaceService"):GetProductInfo(gamepassId)
        if gamepassInfo then
            local buyPrompt = game:GetService("MarketplaceService"):PromptGamePassPurchase(playerId, gamepassId)
            buyPrompt.Completed:Connect(function(purchaseState)
                if purchaseState == Enum.ProductPurchaseDecision.PurchaseGranted then
                    -- The player successfully purchased the gamepass, so let them join the team
                    game.Players.LocalPlayer.Team = team
                end
            end)
        end
    end
else
    warn("Cannot find team with name:", teamName)
end
/```
#

an image for reference

#

there

#

i did it

#
 if game:GetService("GamePassService"):PlayerHasPass(playerId, gamepassId)```
wheat auroraBOT
#

studio** You are now Level 1! **studio

sacred holly
#

there

#

i got this error lua Players.cuentapruebas2.PlayerGui.Team changer.Main.SCP.LocalScript:25: attempt to index nil with 'Completed' - Client - LocalScript:25

#
buyPrompt.Completed:Connect(function(purchaseState)``` this was the line
#

let me check but ty

sacred holly
#

now i got this error lua Unable to cast Instance to int64 - Client - LocalScript:17

#

when fixing the scrip´t i changed line 17 lua if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(playerId, gamepassId) then

#

(btw sorry if im being annoying)

pastel osprey
sacred holly
#

Go to the EvolutionalMaster Profile, hes the owner of the game "Área 405"

pastel osprey
#

Ok?

#

So its not an scp game?

#

yo

wheat auroraBOT
#

studio** You are now Level 2! **studio

pastel osprey
#

@sacred holly

#

is this game in alpha?

sacred holly
#

In development

pastel osprey
#

because im not trying to be rude but the graphics dont look the best

#

ok

#

I though it was released

#

I was about to say

#

Im actually a pro builder/scripter

sacred holly
#

Like the game Is Classic style

pastel osprey
#

?

#

Can I be hired?

#

It will be for part time though

sacred holly
#

Well the owner doesnt wants others people, srry

wheat auroraBOT
#

studio** You are now Level 2! **studio