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

How can I make this script work for players that bought gamepass only ? Script below

I need to make this somehow to work for just the people with the gamepass, its a team changer Script:

script.Parent.MouseButton1Click:Connect(function() workspace.TeamEvents.TeamEvent:FireServer(script.Parent.Text) end)

2 answers

✓ Accepted answer

#LOCAL SCRIPT:

local remote = game.Workspace:WaitForChild("Folder").CheckGamepass

script.Parent.MouseButton1Click:Connect(function() 
	remote:FireServer()  --fires a remote event here to see if the player has the gamepass 


	workspace.TeamEvents.TeamEvent:FireServer(script.Parent.Text) 
end)

#SERVER SCRIPT:

local MarketplaceService = game:GetService("MarketplaceService")
local remote = game.Workspace:WaitForChild("Folder").CheckGamepass


--check to see if the player has the team gamepass
function checkForGamepass(player, gamepassID)
    local succ, hasGamepass = pcall(function()
        return MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassID)
    end)

    if(succ)then
		if hasGamepass then
			print("player owns pass")
       		return true
		else 
			print("player does not have gamepass")
		end
	else
		print("was not successful ", succ)
    end

	return false
end

--this function gets ran when the CheckGamepass remote event gets fired
remote.OnServerEvent:Connect(function(player)
    local hasTeamGamePass = checkForGamepass(player, 7673825)

    if hasTeamGamePass then
        player.Team = game.Teams["GamepassTeam"]
    end
end)

UserOwnsGamePassAsync, this will return whether the given player has a given gamepass.

local GamepassID = -- Your Gamepasses ID
local PlayerID = game.players.localplayer

script.Parent.MouseButton1Click:Connect(function()
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(PlayerID, GamepassID) then 
		workspace.TeamEvents.TeamEvent:FireServer(script.Parent.Text) 
	end
end)

Something like that,

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