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)
Have you considered using the or
operator?
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.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.
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)