Easy Written By UnityWoosh

Gamepass Tools Created on: 30-09-2019

Learn how you can make a gamepass script

INTRO

> Hello, I'm Siewva for 3 years a roblox scripter. I really want, to help people with scripting. Hopefully you enjoy this.

Message me on discord if you need help. Siewva#8888

BEGIN

All Staps (6):

Stap: 1

  • We need to detect when a player joins. This has one argument, the player.

    game.Players.PlayerAdded:Connect(function(Player) -- We now have the player detected. end)

Stap: 2

  • Because StarterGear doesn't always work, I detect when the player spawns.

    Player.CharacterAdded:Connect(function(Character) -- We now have detected our Character. end)

Stap: 3

  • Let we check if the player owns the gamepass with a local function.

    local function CheckGamepass(PlayerId, AssetId) local MarketPlace = game:GetService("MarketplaceService") if MarketPlace:UserOwnsGamePassAsync(PlayerId, AssetId) then return true end return false end

Stap: 4

  • Now we need to add the tool if the player owns it.

    local function AddTool(Player, Tool)

    local Location = game.ServerStorage
    if Location then
    	local GamepassTool = Location:FindFirstChild(Tool)
    	if GamepassTool then
    		local NewTool = GamepassTool:Clone()
    		NewTool.Parent = Player:WaitForChild("Backpack")
    		Player:LoadCharacter()
    	else
    		warn("Tool doesn't exit into the location.")	
    	end
    else
    	warn("Cannot find Location for the gamepass tools.")
    end
    

    end

Stap: 5

  • Now we need to add the last things to let everything works.

    local function CheckGamepass(PlayerId, AssetId)

    local MarketPlace = game:GetService("MarketplaceService")
    if MarketPlace:UserOwnsGamePassAsync(PlayerId, AssetId) then
    	return true
    end
    return false
    

    end

    local function AddTool(Player, Tool)

    local Location = game.ServerStorage
    if Location then
    	local GamepassTool = Location:FindFirstChild(Tool)
    	if GamepassTool then
    		local NewTool = GamepassTool:Clone()
    		NewTool.Parent = Player:WaitForChild("Backpack")
    		Player:LoadCharacter()
    	else
    		warn("Tool doesn't exit into the location.")	
    	end
    else
    	warn("Cannot find Location for the gamepass tools.")
    end
    

    end

    game.Players.PlayerAdded:Connect(function(Player)

    Player.CharacterAdded:Connect(function(Character)
    	if CheckGamepass(Player.UserId, 1234567) then
    		AddTool(Player, 'Glock-18')
    	end
    end)
    

    end)

Stap: 6

  • Do you have more then 1 gamepass? Replace it to this! Don't forget the local functions.

    game.Players.PlayerAdded:Connect(function(Player)

    Player.CharacterAdded:Connect(function(Character)
    	if CheckGamepass(Player.UserId, 1234567) then
    		AddTool(Player, 'Glock-18')
    	elseif CheckGamepass(Player.UserId, 1234567) then
    		AddTool(Player, 'BoomBox')
    	elseif CheckGamepass(Player.UserId, 1234567) then
    		AddTool(Player, 'EarBuds')
    	end
    end)
    

    end)

THE END

More Explanation And Hints:

Stap 5: You need to replace "Location = game.Servertorage" to something else, when you have the tool somewhere else, like: "Location = game.Workspace".

Stap 6: Only needed if you have more then one gamepass in your game. Don't forget to replace the names, like: "EarBuds" to "Scooter".

Remember, this script need to be in a 'Script' and not in a 'LocalScript' >Hopefully you now know how to make a Gamepass Tools script! If you want more tutorials from me, please leave a review!

Easy Written By UnityWoosh

See UnityWoosh's profile on Roblox

Discussion