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

item giver that works only with a gamepass?

heres a script i got and tried to edit, i want to make it where you can get the item onclick if you have the gamepass but if you dont then it asks you to purchase it

local PassId = script["4835177"]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local BloxyCola = ReplicatedStorage:WaitForChild("Bloxy Cola")
local player = game.Players.LocalPlayer

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    if MarketplaceService:UserOwnsGamePassAsync(player, PassId) then -- if they have the gamepass then they get it
        BloxyCola:Clone().Parent = player.Backpack

        for i = 60, 1, -1 do -- give it a 60 second cooldown and show the timer
            script.Parent.BillboardGui.TextBox.Text = tostring(i)
            wait(1)
else
    game:GetService("MarketplaceService")PromtPurchase(player,id) -- if they dont have the gamepass ask them to buy it

        end
    end
end)

the script doesn't work at all and I don't know why. could someone please point out some mistakes that stop it from working? any help is very appreciated:)

4 comments

0

What exactly is PassId?

0

It's the gamepass ID

0

Make sure its in a server script if not alread

0

i moved it into serverscriptservice and changed all of the directories. no luck :(

1 answer

✓ Accepted answer

That code isn't going to work ever. first of all you need to change the pass id to an actual number.

local PassId = 4835177 -- assuming thats the id

It is quite evident that you copy and pasted it from a tutorial and forgot to change a lot of things as there is multiple errors in this. You are missing ends and all sorts of stuff. This should be in workspace and in a script not a LocalScript. And if its in a Script it can't index the local player.

local PassId = 4835177
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local BloxyCola = ReplicatedStorage:WaitForChild("Bloxy Cola")

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    if MarketplaceService:UserOwnsGamePassAsync(player, PassId) then -- if they have the gamepass then they get it
        BloxyCola:Clone().Parent = player.Backpack

        for i = 60, 1, -1 do -- give it a 60 second cooldown and show the timer
            script.Parent.BillboardGui.TextBox.Text = tostring(i)
            wait(1)
		end
	else
    	game:GetService("MarketplaceService"):PromtPurchase(player,PassId) -- if they dont have the gamepass ask them to buy it
    end
end)

That code should work. Accept this answer if it did

3 comments

0

no sadly it wont work on my end. I'm probably doing something wrong

0

This was not copied from a tutorial, this was copied from me. I just forgot to add the .Value, PassId object was an IntValue.

0

There was a lack of syntax and just general bad coding like setting the id variable to a member inside the script that doesn't exist and not calling the right variable name when indexing it the 2nd time

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