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!
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.
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.
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.
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:
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)