Keycard Gamepass Problem

Hello fellow Robloxians,

I’ve been getting back into scripting and building and so, I am working on a project that takes place in a facility of sorts. In this facility, I have a gamepass that allows you to buy a level 2 keycard for a small fee. While the door worked when I had the card placed in the starterpack, when I have it moved to a players backpack after they’ve purchased it, it doesn’t function. I also have a door that uses a Level 1 keycard and a Level 2 keycard. The level 1 card functions fine with the door, but the level 2 card does not. I don’t know if this has to do with the card being in ReplicatedStorage and then moved to the player’s backpack, or if it is something else.

I’ve tried altering the MarketPlaceService scripts but to no avail, same goes for the Card Reader script. Below is the code for the card reader.

local reader = script.Parent
local door = script.Parent.Parent.door

reader.Touched:Connect(function(hit)
	if hit.Parent.Name == "Card2" then --If touched by card2, then open the door
		door.Transparency = 1
		door.CanCollide = false
		wait(2)
		door.Transparency = 0
		door.CanCollide = true
	end
end)

If you need more details or such I am happy to provide the details you need, but I just can’t seem to find a solution. Thanks!

2 Likes

Can you list the card tool’s hierarchy?

1 Like

What do you mean by “inventory”, do you mean backpack?

Here is the hierarchy for the GUIs, Card Reader, and the Card Tool, I’m providing all just in case. (Please disregard the Tip GUI)

Screen Shot 2020-05-18 at 9.23.06 PM Screen Shot 2020-05-18 at 9.23.14 PM Screen Shot 2020-05-18 at 9.23.23 PM

1 Like

Yes, I use inventory instead of backpack as thats what I prefer to call it

1 Like

What does the reader script have anything to do with the gamepass? Isn’t the problem the gamepass?

Hmm. I cannot see anything wrong with this script. Does the game insert the card correctly?

I have a Level 1 keycard and a door that uses both Levels. Card 1 works with said door, but Card 2 doesn’t, I should’ve put that in the post to be more clear and shall update it.

Is the card by any chance created locally? Also try printing the name of hit’s parent in the event

I tried using a print statement to see what the problem is. Whenever I try to use the card, the function registers and it is fired. But the if statement does not run, unlike the function.

I just tested something that looks like your system(Except without the gamepass), and it actually worked.

What does the gamepass script look like?

1 Like

That is why I am confused. The Keycard system I have was working without the gamepass, but once I implemented the gamepass, it just seemed to stop working.

Can you give me the id of the gamepass? (Or the gamepass code.)

The Card2Local Script looks like this:

local player = game.Players.LocalPlayer

local ownsGamepass = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,9599322)

if ownsGamepass then

local card2 = game:GetService("ReplicatedStorage"):WaitForChild("Card2"):Clone()

card2.Parent = player.Backpack

end

The Local Script inside of the Card2Gui looks like this:

script.Parent.MouseButton1Click:Connect(function()
game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer,9599322)
end)

Here is also the tree for the GUIs, please disregard the Tips GUI

!Screen Shot 2020-05-18 at 9.23.14 PM|394x196

The ID for the gamepass is: 9599322

Hm, in the code that checks if the user has the Card2, couldn’t you just check if the user owns the gamepass, then if he does, give access?

Also, i honestly think putting the card2 in the ServerStorage(Not ReplicatedStorage), would be better.

Try using this code:

-- ServerScript, in ServerScriptService.

game.Players.PlayerAdded:Connect(function(plr)
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,9599322) then
		local Card2Clone = game.ServerStorage:WaitForChild("Card2"):Clone()-- I will suppose you have putten the card in serverstorage.
		Card2Clone.Parent = plr:WaitForChild("Backpack")
    end
end)
1 Like

Don’t create the tool locally, the tool won’t be present for the server, so the event won’t fire.

1 Like

I could try this as an alternative if I can’t find a definitive solution.

1 Like

Do You Now Have A Solution On This?