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

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

Asked by 4 years ago

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

Log in to vote
1
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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)
Ad
Log in to vote
0
Answered by
Benbebop 1049 Moderation Voter
4 years ago
Edited 4 years ago

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,

Answer this question