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
/```
** You are now Level 1! **