Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

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

✓ Accepted answer

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

3 comments

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

0

Nevermind. Checked the script analysis tool in the roblox studio forgot an ")" so thanks :D U made my day

0

ur welcome. also, i fixed the code above as well lol, silly me! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.