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

How to add Gamepass Compatibility into this script?

Asked by 4 years ago

This is a follow up on an earlier question. Shoutout to AntoninFearless who helped me get the main function of it working. Thank you so much! You're a total life saver.

The main function of this script is to summon tools into a player's Backpack upon saying a command. For instance, saying "/town guard" gives the player tools associated with a Town Guard. Rinse and repeat for various different types of characters and their tools. This part works out perfectly and it's all good.

What I can't figure out how to do is add Game Pass compatibility to this script. As far as I know, the game pass service is outdated or something. I know that it has to do something with marketplace, but I haven't learned how all that works yet. I'm still a novice at scripting.

Btw, the tools are stored in a folder called "Tools" in ReplicatedStorage. The script copies them from there.

The script is written a bit differently in the game pass section, but it still works perfectly. The part of the script that limits the game pass section is just what needs to be patched.

Below is my current version of the script. The game pass block has -- in front of it so that it's not active yet and the Fairy command still works. To test it, replace the command name with whatever you want and names of the tools with the actual names of the tools.

Thanks in advance for the help!

function onChatted(msg, speaker)
    local source = string.lower(speaker.Name)
    msg = string.lower(msg)
    if msg == "/town guard" then
            local townguard1 = game.ReplicatedStorage.Tools:FindFirstChild("Knight's Emberblade")
            local townguard2 = game.ReplicatedStorage.Tools:FindFirstChild("Knight's Poisonblade")
            local townguard3 = game.ReplicatedStorage.Tools:FindFirstChild("Knight's Sparkblade")
            townguard1:Clone().Parent = speaker.Backpack
            townguard2:Clone().Parent = speaker.Backpack
            townguard3:Clone().Parent = speaker.Backpack
    elseif msg == "/aragin" then
            local aragin1 = game.ReplicatedStorage.Tools:FindFirstChild("Aragin's Giga Hammer")
            local aragin2 = game.ReplicatedStorage.Tools:FindFirstChild("Aragin's Rustic Arsenal")
            local aragin3 = game.ReplicatedStorage.Tools:FindFirstChild("Aragin's Toxic Terrain")
            aragin1:Clone().Parent = speaker.Backpack
            aragin2:Clone().Parent = speaker.Backpack
            aragin3:Clone().Parent = speaker.Backpack
    end
end

game.Players.PlayerAdded:connect(function(player)
    -- if Game:GetService("GamePassService"):PlayerHasPass(player, INSERT_GAMEPASS_ID_HERE) then
    player.Chatted:connect(function(msg) onChatted(msg, player)

    if msg == '/fairy' then
            local fairy1 = game.ReplicatedStorage.Tools:FindFirstChild("Fairy's Apple")
            local fairy2 = game.ReplicatedStorage.Tools:FindFirstChild("Fairy's Searing Wings")
            local fairy3 = game.ReplicatedStorage.Tools:FindFirstChild("Fairy's Spoon")
            fairy1:Clone().Parent = player.Backpack
            fairy2:Clone().Parent = player.Backpack
            fairy3:Clone().Parent = player.Backpack
        end
    end)
    --end
end)

-- Replace "INSERT_GAMEPASS_ID_HERE" with a Game Pass ID.

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Hello, in order to do this you have to put a script in serverscriptservice and put the following:

local gamepassid = 8087490 --Change this to your gamepass id
local mj = game:GetService('MarketplaceService')

game.Players.PlayerAdded:connect(function(player) -- gets player
    player.CharacterAdded:connect(function(Character)
        if mj:UserOwnsGamePassAsync(player.UserId,gamepassid) then
            player.Chatted:connect(function(msg)
                local speaker = player
                print(speaker)
                if msg == '/town guard' then
                    local gun = game.ReplicatedStorage.handgun
                    local sniper = game.ReplicatedStorage.sniper
                    local sword = game.ReplicatedStorage.sword
                    gun:Clone().Parent = speaker.Backpack
                    sniper:Clone().Parent = speaker.Backpack
                    sword:Clone().Parent = speaker.Backpack
                end
            end)
        end
    end)
end)

The tools I used are just examples If this doesn't work, notify me.

0
The gamepass might take time to load into your game, it will work in studio and not in the game it self. If your gamepass finally loads in and you see it in your game store and doesn't work, let me know AntoninFearless 622 — 4y
Ad

Answer this question