Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago

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

Log in to vote
0
Answered by
C1RAXY 81
2 years ago
Edited 2 years ago

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!

Ad

Answer this question