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

How can I connect a gamepass to a button?

Asked by 7 years ago

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.

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

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

0
Thanks a bunch, that is clever. Dekadrachm 50 — 7y
0
I still get an error, 00:12:24.171 - Not a valid Player .Technology Data Entertainment.Buttons.10% Chance for VIP lucky blocks, all droppers. - [VIP].Script', Line 5 at first I thought I was because I was in the editor, but I published and went to my game only to find out it still didn't work. I have the game pass since I made it. Dekadrachm 50 — 7y
0
I ran a server test, but when I walked over the button, nothing happened. It didnt give any errors or print anything, this is weird... Dekadrachm 50 — 7y
0
When in a roblox server, the button works proeprly, but it doesnt seem to be applying the script. Is there a way I can debug in that mode? Dekadrachm 50 — 7y
View all comments (2 more)
0
Its most likely an error on my side, I can't seem to figure out what would be wrong, since everytime a button I have is clicked to spawn blocks, it checks if the VIP value has changed and if it is = to "true" then it spawns a vip block. I even manually set the vip value to "true" and the game worked fine in Roblox Studio Dekadrachm 50 — 7y
0
I'm sure at your end it is fine, I'll ask a new question. Dekadrachm 50 — 7y
Ad

Answer this question