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

Why is my LocalScript not doing anything? Print test prints nothing?

local MarketplaceService = game:GetService("MarketplaceService")
local Player = game.Players.LocalPlayer

local doorPart = game.Workspace.LoungeDoor
local gamepassId = 12555974

Player.CharacterAdded:Connect(function()
    if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, gamepassId) then
        print("Player owns pass.")
        doorPart.CanCollide = false
    else
        print("Player does not own pass.")
        doorPart.CanCollide = true
    end
end)

Nothing happens at all. No prints, nothing.

1 answer

Well, CharacterAdded and PlayerAdded doesn't seem to work in a Local Script. Also, I suggest handling MarketplaceServices in Server scripts, as Local scripts can be modified by exploiters. Also, you can use UserOwnsGamepassAsync as well as PromptGamepassFinished. The latter triggers when a player successfully purchases a gamepass.

Here's an example of using both :

-- Server Script in ServerScriptService

--//Variables
local MP = game:GetService("MarketplaceService")
local gamepassId = 12555974

--//Functions
function gamepassOwner(player, gamepassId)
	local userid = player.UserId
	if MP:UserOwnsGamePassAsync(userid, gamepassId)
		-- Do whatever you want, if user owns the gamepass
		-- Here, I assume you are setting CanCollide of doors locally, so you can use RemoteFunctions or RemoteEvents.
	else
		-- Do whatever you want, if user does not own the gamepass
	end
end

function purchaseGampass(player, gamepassIdd, Purchased) -- It includes three parameters, the player who bought the gamepass, the id of the gamepass, whether the purchase was succesful
	if Purchased then -- If the transaction was successful
		if gamepassIdd == gamepassId then -- If the gamepass id stated above was purchased
			-- Do whatever you want to do if user purchases the gamepass
		end
	else
		-- Do whatever you want to do if user doesn't purchase the gamepass
	end
end	

--// Main
game.Players.PlayerAdded:Connect(gamepassOwner)
MP.PromptGamePassPurchaseFinished:Connect(purchaseGamepass)

Lemme know if it helps!

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