Ad
Log in to vote
0

SF gamepass

Asked by 7 years ago

Ok so I have a Sword Fighting Tournament game and I have a gamepass that give's you a special sword if you have it, well it's like TheGamer101's Krimson Katana game pass. So anyway I was wondering how to make it so that you don't get the sword until the game start's can anyone show me please?

--------------------
--| WaitForChild |--
--------------------

-- Waits for parent.child to exist, then returns it
local function WaitForChild(parent, childName)
    assert(parent, "ERROR: WaitForChild: parent is nil")
    while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
    return parent[childName]
end

-----------------
--| Variables |--
-----------------

local GamePassService = Game:GetService('GamePassService')
local PlayersService = Game:GetService('Players')
local InsertService = Game:GetService('InsertService')
local LightingService = Game:GetService('Lighting') --TODO: Use new data store service once that exists

local GamePassIdObject = WaitForChild(script, 'GamePassId')
local ToolAssetsToLoad = WaitForChild(script, 'ToolAssetsToLoad')

local AdminTools = LightingService:FindFirstChild('AdminTools')

-----------------
--| Functions |--
-----------------

-- Makes copies of all the admin tools and puts them in target
local function CloneAdminTools(target)
    for _, tool in pairs(AdminTools:GetChildren()) do
        local toolClone = tool:Clone()
        toolClone.Parent = target
    end
end

-- When a player with the game pass joins, give them the admin tools
local function OnPlayerAdded(player)
    if GamePassService:PlayerHasPass(player, GamePassIdObject.Value) then
        local starterGear = WaitForChild(player, 'StarterGear')
        CloneAdminTools(starterGear)
        if player.Character then -- They've already loaded and won't get their StarterGear until next spawn
            local backpack = WaitForChild(player, 'Backpack')
            CloneAdminTools(backpack)
        end
    end
end

--------------------
--| Script Logic |--
--------------------

-- Create AdminTools if it doesn't exist
if not AdminTools then
    AdminTools = Instance.new('Model')
    AdminTools.Name = 'AdminTools'

    -- Load all of the assets in ToolAssetsToLoad and put them in AdminTools
    for _, intObject in pairs(ToolAssetsToLoad:GetChildren()) do
        if intObject and intObject:IsA('IntValue') and intObject.Value then
            local assetModel = InsertService:LoadAsset(intObject.Value)
            if assetModel then
                local asset = assetModel:GetChildren()[1]
                if asset then
                    asset.Parent = AdminTools
                end
            end
        end
    end

    AdminTools.Parent = LightingService
end

PlayersService.PlayerAdded:connect(OnPlayerAdded)

0
This is my Gamepass script omarz123 5 — 7y

4 answers

Log in to vote
2
Answered by 1 year ago
yeet
Ad
Log in to vote
1
Answered by 1 year ago
yeet
Log in to vote
0
Answered by
Everesty 1001 Moderation Voter
7 years ago

You can use the PlayerHasPass method to check if the user has the game pass, if they do, then clone the sword you want to give to them somewhere where it can be found when the player is put into the game.

Log in to vote
0
Answered by
Nytroz 15
7 years ago

You will also need the ID's of the GamePasses so Roblox knows what GamePass you are checking for in your game. I've started you off with:

local id = [GamePassIDGoesHere]

game.Players.PlayerAdded:connect(function(player)
    if Game:GetService("GamePassService"):PlayerHasPass(player, id) then 

Answer this question