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)
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! :)