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

How would I give certain users access to a gamepass item?

Asked by 8 years ago

I have this script, where when the user buys the gamepass they'll spawn with a sword in their inventory. However, the game is a group game and I don't want to fork over 450 robux to myself to buy the sword. How exactly would I add in something that said I have VIP access to the sword?

--Script made by OpticUniversse in collaboration with Optic Studios.
--Additional help by __________ (insert yourname here)


id = 484193252
game.Players.PlayerAdded:connect(function(plr)
repeat wait() until plr.Character
if Game:GetService("GamePassService"):PlayerHasPass(plr, id) then
tool = game.ServerStorage["Yellow Neon"]
tool:clone().Parent = plr.Backpack
tool:clone().Parent = plr.StarterGear
end
end)

1 answer

Log in to vote
1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

Problem

Have you considered using the or operator?


Solution

  • The or operator tells the script, alright if the first thing is wrong we'll check if this next thing is right. So if the PlayerHasPass returns false, you would have the or operator detect if the player has your name.

Recommendation

Do not use GamepassService. The issue with GamepassService is it caches the result you initially receive. That means the player will not be able to get game pass items until they join a new server. You should be using MarketplaceService's PlayerOwnsAsset function to get a result.

However, if you do go the MarketplaceService route, you would need to look into the CharacterAdded event and you wouldn't be using StarterGear. I do believe I've heard at one point StarterGear doesn't work as intended in FilteringEnabled settings, however, I am unaware if this issue has been resolved.


Final Script

The only thing I did change was adding the or operator to the if-then statement and changed the GamepassService to MarketplaceService functions.

--Script made by OpticUniversse in collaboration with Optic Studios.
--Additional help by __________ (insert yourname here)


id = 484193252

game.Players.PlayerAdded:connect(function(plr)
    repeat wait() until plr.Character
    if Game:GetService("MarketplaceService"):PlayerOwnsAsset(plr, id) or plr.Name == "OpticUniversse" then --All I added was the "or the player's name is OpticUniversse"
        tool = game.ServerStorage["Yellow Neon"]
        tool:clone().Parent = plr.Backpack
        tool:clone().Parent = plr.StarterGear
    end
end)

Hopefully, this answered your question. If it did, do not forget to hit the accept answer button. If you have any questions, feel free to comment below.
Ad

Answer this question