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

What is wrong with this gamepass code i put in a local script?

i put this script in a door for a vip room. It is meant to prompt a gamepass purchase when you touch it. I put it in a local script and nothing is even printing. Why?

local id = 33857923
print("launched")
script.Parent.Touched:Connect(function(plr)
	print("touched")
	game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, id)
end)

1 answer

#It took me a while to code a solution since I'm not quite good at this, but I got your solution.

Issues:

1: It's not printing because it's a Local Script

2: You have to define a player with the variable plr

Solution:

You need to script it inside the part you want to be the trigger of the Prompt, if you do it like a Local Script it will only trigger for the part but not other clients.

Now that you did that, all you have to do is just define who is the player, which is any parent that has the name of a player in Players.

local gamepass = 33857923

local part = script.Parent
local characters = game:GetService("Workspace")
local players = game:GetService("Players")

cooldown=false
part.Touched:Connect(function(touching)
	if not cooldown then cooldown=true 
		if touching:IsA("Part") or touching:IsA("MeshPart") then
			for i,player in pairs(players:GetChildren()) do
				if player.Name == touching.parent.name then -- Check if player matches the parent
					print("Success || PLR:"..player.Name)
					game:GetService('MarketplaceService'):PromptGamePassPurchase(player, gamepass)
					wait(5)
					cooldown=false
				end
			end
		end	
	end
end)

Hope it helps, I tried my best lol!

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