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

How to insert gear from gamepass?

Asked by 5 years ago

My script is inside of ServerScriptService and I'm trying to make it if you have the gamepass then it'll insert a gear into your backpack.

Note: I made it able so if you have the gamepass, it gives you a little title above your head, but can't figure out how to insert physical tools/models.

Here is the script:

local MS = game:GetService("MarketplaceService")
local VIPID = 7139894

local RS = game:GetService("ReplicatedStorage")

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        if MS:UserOwnsGamePassAsync(Player.UserId,VIPID)then 
            local Head = Character:WaitForChild("Head")
            local VIP = RS:WaitForChild("VIP"):Clone()
            VIP.Adornee = Head
            VIP.Parent = Head

-- The rest is my sad attempt of trying to insert the gear from ReplicatedStorage to Backpack.
            local BP = Character:WaitForChild("Backpack")
            local VIP2 = RS:WaitForChild("FirstAid"):Clone()
            VIP2.Parent = Backpack      
        end     
    end)
end)

1 answer

Log in to vote
0
Answered by 5 years ago

You were missing some assets for the script to Search the Players.

**[Couldn't add the VIP because i don't know what is it for. So hopefully you can edit this script for that!] **

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = 7139894-- Change this to your game pass ID 
local RS = game:GetService("ServerStorage")

function onPlayerSpawned(player) 
    local hasPass = false
    -- Check if the player already owns the game pass
    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID)
  print("Has the Pass!")
    end)
    -- If there's an error, issue a warning and exit the function
    if not success then
        warn("Error while checking if player has pass: " .. tostring(message))
        return
    end
    if hasPass == true then
  RS.FirstAid:clone().Parent = player.Backpack
 end
end
game.Players.PlayerAdded:Connect(function(player)
  player.CharacterAdded:Connect(function()
    onPlayerSpawned(player)
  end)
end)
-- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function
Players.CharacterAdded:Connect(onPlayerSpawned)
Ad

Answer this question