Hello, I am still fairly new to scripting and was looking online about how to check if players have a game pass when they join, I got that working. However, I am creating a tycoon map and one of the tycoon buttons require a VIP pass, I need to check if the person touching the button has a vip pass and if they do I need to change a stored string value to "true". The script I currently am having issues with is below.
Script with errors.
local gamePassId = 445136135 function vip(player) game:GetService("GamePassService") bool PlayerHasPass ( Player player, int gamePassId ) print(player.Name .. " has the game pass!") script.Parent.Parent.Parent.VIP.Value = "true" print(player.Name .. " doesn't have the game pass...") end end vipbutton = script.Parent.Head vipbutton.Touched:connect(vip)
My Boolean function isn't working, I'm sure to your guy's more experienced eyes, you see some noob mistake. The Boolean function is quite literally copy/pasted from the wiki on handling game passes, The Boolean wants an equals sign. The wiki says that the function depending if true will return a true for PlayerHasPass. I'm not sure what I'm doing wrong, since I'm new, I usually just mash code together until it works properly, so far that has been a semi success.
Thanks in advance, the wiki page also has this:
void SetPlayerHasPassUrl ( string playerHasPassUrl ) [LocalUserSecurity]
To my understanding, the above code isn't needed for what I'm trying to achieve.
Thanks again
-That one noob nobody likes.
You need to check if the player has the gamepass or not using the PlayerHasPass method of the GamePassService. To do this you can use if statements. If statements will check if something is true or false. game.GamePassService:PlayerHasPass(player, passId) will return true if the player owns the pass or false if the player does not. Knowing this we can check if they have the pass by doing the below:
if game:GetService("GamePassService"):PlayerHasPass(player, gamePassId) then print(player.Name .. " has the game pass!") else print(player.Name .. " doesn't have the game pass...") end
Updated code:
local gamePassId = 445136135 local passService = game:GetService("GamePassService") function vip(player) if passService:PlayerHasPass(player, gamePassId) then print(player.Name .. " has the game pass!") script.Parent.Parent.Parent.VIP.Value = "true" else print(player.Name .. " doesn't have the game pass...") end end end vipbutton = script.Parent.Head vipbutton.Touched:connect(vip)
Alternatively you can also use game:GetService("MarketplaceService"):PlayerOwnsAsset(player, gamePassId) to check if they own a pass instead of the GamePassService, if you should ever want to; http://wiki.roblox.com/index.php?title=API:Class/MarketplaceService/PlayerOwnsAsset