Script print purchase

— how do I make it print a purchase of the player doesn’t own a game pass? Idk how to do it
local MarketplaceService = game:GetService(“MarketplaceService”)

local Player = script.Parent.Parent.Parentlocal GamePassId = 162872866

local HasPass = false

local success, message = pcall(function()

HasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId,GamePassId)

print(HasPass)

end)

if HasPass == true then

Player.Team = game.Teams.Imam

end

local Opened = false

local Teams = game:GetService(“Teams”)

script.Parent.Team.MouseButton1Click:Connect(function()

if Opened == false then

script.Parent.Frame:TweenPosition(UDim2.new(0.236, 0,0.266, 0))

Opened = true

else

script.Parent.Frame:TweenPosition(UDim2.new(0.236, 0,-0.9, 0))

Opened = false

end

end)

script.Parent.Frame.Imam.MouseButton1Click:Connect(function()

if HasPass == true then

script.Parent.Parent.Parent.Team = Teams.Imam

script.Parent.Parent.Parent.Team.TeamColor = Teams.Imam.TeamColor

wait()

script.Parent.Parent.Parent:LoadCharacter()

end

end)

script.Parent.Frame.Normal.MouseButton1Click:Connect(function()

script.Parent.Parent.Parent.Team = Teams.Normal

script.Parent.Parent.Parent.Team.TeamColor = Teams.Normal.TeamColor

wait()

script.Parent.Parent.Parent:LoadCharacter()

end)

If the player can only be spawned in as Imam(team) if the player changes his team to Normal he can not change it back. How do I fix this? MODEL ID:13132641394

I had a heart attack reading that code, please learn to actually program before posting questions that are clearly easy to do. Also, use code blocks for your code like:
```
code
```
it’ll be:

code

anyways, here’s your code corrected and made better.

local marketplaceService = game:GetService("MarketplaceService")
local teams = game:GetService("Teams")

local player = script.Parent.Parent.Parent

local gamePassId = 162872866

local hasGamepass = false
local opened = false

local success, message = pcall(function()
	hasGamepass = marketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassId)

	print(hasGamepass)
end)

player.Team = hasGamepass and teams.Imam or player.Team

script.Parent.Team.MouseButton1Click:Connect(function()
	script.Parent.Frame:TweenPosition(
		opened and UDim2.new(0.236, 0,-0.9, 0) or
			UDim2.new(0.236, 0,0.266, 0)
	)

	opened = not opened
end)

local function switchTeam(team: Team)
	player.Team = team
	player.Team.TeamColor = team.TeamColor

	task.wait()

	player:LoadCharacter()
end

script.Parent.Frame.Imam.MouseButton1Click:Connect(function()
	if not hasGamepass then
		return marketplaceService:PromptGamePassPurchase(player, gamePassId)
	end

	switchTeam(teams.Imam)
end)

script.Parent.Frame.Normal.MouseButton1Click:Connect(function()
	switchTeam(teams.Normal)
end)

marketplaceService.PromptGamePassPurchaseFinished:Connect(function(_player, _gamePassId, wasPurchased)
	if not wasPurchased then return end
	if player ~= _player then return end
	if gamePassId ~= _gamePassId then return end
	
	hasGamepass = true
	
	print("Bought successfully.")
end)
1 Like

Can you please send a localfile, so I can get way less confused?

Never mind, there’s a model link, I’m actually dumb.

Anyways, I may or may have not fixed it:

--locals--
local MarketplaceService = game:GetService("MarketplaceService")
local Game = script.Parent.Parent.Parent
local Player = Game.Players.LocalPlayer
local GamePassId = 162872866
local HasPass = script.HasPass
local ChooseTeamGui = script.Parent
local Frame = ChooseTeamGui.Frame
local TeamButton = ChooseTeamGui.Team
----------
--pcall function--
local success, message = pcall(function()
	HasPass.Value = MarketplaceService:UserOwnsGamePassAsync(Player.UserId,GamePassId)
	if not MarketplaceService:UserOwnsGamePassAsync(Player.UserId,GamePassId) then
		HasPass.Value = false -- I mean it'll not change since the player must own it
		if Player.DisplayName == Player.Name then
			print(Player.Name.." doesn't have "..MarketplaceService:UserOwnsGamePassAsync(Player.UserId,GamePassId).." gamepass")
		elseif Player.DisplayName ~= Player.Name then
			print(Player.DisplayName.."(@"..Player.Name..") doesn't have "..MarketplaceService:UserOwnsGamePassAsync(Player.UserId,GamePassId).." gamepass")
		end
	elseif MarketplaceService:UserOwnsGamePassAsync(Player.UserId,GamePassId) then
		if Player.DisplayName == Player.Name then
			HasPass.Value = true
			print(Player.Name.." has "..MarketplaceService:UserOwnsGamePassAsync(Player.UserId,GamePassId).." gamepass")
		elseif Player.DisplayName ~= Player.Name then
			print(Player.DisplayName.."(@"..Player.Name..") has "..MarketplaceService:UserOwnsGamePassAsync(Player.UserId,GamePassId).." gamepass")
		end
	end
end)
------------------
--if player owns the gamepass--
if HasPass.Value == true or MarketplaceService:UserOwnsGamePassAsync(Player.UserId,GamePassId) then
	Player.Team = game.Teams.Imam
end
-------------------------------
--more locals--
local Opened = false
local Teams = game:GetService("Teams")
---------------
--making the team button work--
TeamButton.MouseButton1Click:Connect(function()
	if Opened == false then
		Frame:TweenPosition(UDim2.new(0.236, 0,0.266, 0))
		Opened = true
	else
		Frame:TweenPosition(UDim2.new(0.236, 0,-0.9, 0))
		Opened = false
	end
end)
-------------------------------
--making the Imam button work--
Frame.Imam.MouseButton1Click:Connect(function()
	if HasPass.Value == true then
		Game.Team = Teams.Imam
		Game.Team.TeamColor = Teams.Imam.TeamColor
		wait()
		Game:LoadCharacter()
	end
end)
-------------------------------
--making the Normal button work--
Frame.Normal.MouseButton1Click:Connect(function()
	Game.Team = Teams.Normal
	Game.Team.TeamColor = Teams.Normal.TeamColor
	wait()
	Game:LoadCharacter()
end)
---------------------------------

Also, the comments are been made by me, so don’t blame me that I added it, it wasn’t there, before, but now it’s there by me.

Also, add HasPass BoolValue.

1 Like