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

If has gamepass allow him into the job. (On click) Help?

Asked by 8 years ago

So I made this pole at the spawn and I would like that if you click it you change to the job(team) if you have the gamepass. But if you don't have the gamepass you will be prompted to purchase it.

  • GamePass: https://www.roblox.com/library/553074879/VMS-Pass

  • Script \/\/\/\/\/\/

function onClicked(playerWhoClicked)
        game.Players.PlayerAdded:connect(function(player)
        if Game:GetService("GamePassService"):PlayerHasPass(player, 553074879) then 
            player.Team = game.Teams.VMS)
        else
            game.Players.PlayerAdded:connect(function(player)
            game:GetService("MarketplaceService"):PromptPurchase(player, 553074879)
        end
    end)
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

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

PlayerHasPass is not recommended to use now. Try PlayerOwnsAsset. It works the same but more efficient than PlayerHasPass.

Also, you don't need to connect another event to a function. You can just use the playerWhoClicked parameter returned by the MouseClick event.

Here! Let me show you how to fix the script:

local gamepassID = 553074879 -- Your Gamepass ID here! :D

script.Parent.ClickDetector.MouseClick:connect(function (playerWhoClicked)
    local player = playerWhoClicked -- Just a variable for playerWhoClicked.
    local mps = game:GetService("MarketplaceService") -- A variable for MarketplaceService.
    local playerHasPass = mps:PlayerOwnsAsset(player, gamepassID)

    if playerHasPass then
        player.Team = game.Teams.VMS
    else
        mps:PromptPurchase(player, gamepassID)
    end
end)

If you have any questions, please leave a comment below. Thank you and I hope this will help! :)

0
So I checked the script today and it doesn't work. When I check the output it gives nothing. I have an image of the explorer + script. http://imgur.com/a/EopT1 SamDeNormaleAap 0 — 8y
0
Nevermind. Checked the script analysis tool in the roblox studio forgot an ")" so thanks :D U made my day SamDeNormaleAap 0 — 8y
0
ur welcome. also, i fixed the code above as well lol, silly me! :) starlebVerse 685 — 8y
Ad

Answer this question