Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Rainbow Magic carpet GamePass?

It works if you don't own gamepass but if you own gamepass and join you don't have it in backpack I was doing this in studio

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local MagicCarpet = ReplicatedStorage:WaitForChild("GamePassItems"):WaitForChild("RainbowMagicCarpet")
local gamepass_id = 10008706

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		MPS:UserOwnsGamePassAsync(player.UserId, gamepass_id)
	end)
end)

MPS.PromptGamePassPurchaseFinished:Connect(function(Player, gamepass_id, isPurchased)
	if isPurchased == true then
	MagicCarpet:Clone().Parent = Player.Backpack
	elseif isPurchased == false then
	print("Player did not purchase game pass!")
	end
end)

1 answer

you would check with MarketPlaceService:UserOwnsGamePassAsync the code in MarketPlaceService.PromptGamePassPurchaseFinished seems like it could do the job for player.CharacterAdded, just set "isPurchased" with MarketPlaceService:UserOwnsGamePassAsync

for example:

player.CharacterAdded:Connect(function()
	local isPurchased = MPS:UserOwnsGamePassAsync(player.UserId, gamepass_id);
	if isPurchased then
		MagicCarpet:Clone().Parent = Player.Backpack
	else
		print("Player does not own game pass!")
	end
end)

also i would recommend this gamepass stuff be in a server script rather than a LocalScript as if it were in the latter nobody would see the carpet

1 comment

0

I have it in a server script and I did like you said and I get this error 14:03:13.164 - ServerScriptService.Script:8: attempt to index nil with 'CharacterAdded'

This discussion is preserved as it was. New answers, comments, and votes are closed.