Can I check if Roblox Studio if I have bought my gamepass?
I’m trying to make 2 gamepasses that gives you some item (sword) when buyed.
The thing is: When I buy it, and then rejoin the session (Im on roblox studio. Just press “Close” and then “Play” again), the game just forgets that purchase as I’ve never purchased it before. And I dont want to spend robux to check if each item is working fine…
I know that there is a UserOwnsGamePassAsync function but as I’ve said it returns false for me like I’ve never purchased certain item before.
Is it possible to check if I own a gamepass in Roblox Studio?
The thing is its a test purchase, it doesn’t save the purchase, I don’t think atleast.
You should make a datastore for your items where you store the purchased items.
local DataStoreService = game:GetService("DataStoreService")
local ItemDataStore = DataStoreService:GetDataStore("Items")
game.Players.PlayerAdded:Connect(function(Player)
local PurchasedItems= Instance.new("Folder", Player) --or You can make it a table PurchasedItems{}
PurchasedItems.Name = "Items"
local ItemData = ItemDataStore:GetAsync(Player.UserId)
game.Players.PlayerRemoving:Connect(function(Player)
local SaveData = {}
for _,Child in pairs(Player.Items:GetChildren())do
table.insert(SaveData,Child.Value)
ItemDataStore:SetAsync(Player.UserId, SaveData)
end)
end)
also this is not a good datastore I recommend tutorials on advanced ones
But the roblox should remember the purchase from UserOwnsGamePassAsync function.
Going to the published game wont work since I have to paid for the gamepass
Instead of using UserOwnsGamepassAsync make a list of players (using their UserIds) that stores all the players you want to have the game pass, I believe that’s how gamepass gifting works.
It would look like this, have this function:
local MSS = game:GetService("MarketPlaceService")
local playersWithGamepass = {
111111 = {
111111 -- Game pass ids here
}
} -- Add user ids here
function ownsGamepass(userId,gamepassId)
if MSS:UserOwnsGamepassAsync(userId, gamepassId or table.find(playersWithGamepass then
local usersGamepasses = playersWithGamepass[userId]
if table.find(usersGamepasses, gamepassId then return true end
end
return false
end
-- Use:
game.Players.PlayedAdded:Connect(function(player)
local gamepassId = 111111 --Gamepass ID here
local owns = ownsGamepass(player.UserId, gamepassId)
if owns then
print("Owns")
else
print("Doesn’t own")
end
end)
In the script of giving the gamepass owner the gamepass thing you can make OR if player userid is yours then it does what the gamepass does to others who own the gamespass, but for you you don’t need it you just have to be you
I know what you’re saying. If I wanted to give myself an item itself then sure I’d use that method but I actually want to give myself a gamepass itself. And we agreed there is no way to do that without paying ;c
that table would probably need to save actually, but @TracerBH I suggest the or if Player.UserId = --your userid if you just want yourself to have it aswell as the gamepass owners, that is what is the easiest solution for your problem It doesn’t give you the gamepass , but it literally gives the same perks so its the same thing except you don’t own the roblox gamepass asset, but that doesn’t really matter since you are the owner and you make the rules of you experience