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

How do I create a gamepass that gives a player a tool every time they spawn?

Asked by 5 years ago

--My code is:

local id = 6485848 local barret = game.ServerStorage:FindFirstChildOfClass("Tool")

game.Players.PlayerAdded:Connect(function(player) if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.userId,id) then local barretClone = barret:Clone() barretClone.Parent = player:WaitForChild("Backpack") end end)

--This script only adds the tool only when the player enters the game, not when they spawn. I tried using CharacterAdded but that is not a child of players, any suggestions?

0
That only fires once per session, do character added, it says it's not a child of players because you did it wrong SuperSamyGamer 316 — 5y

1 answer

Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

try this script, place it in the ServerScriptStorage

local gpid = 6331302 -- Gamepass ID
tools = {"HasSpeedPassBool"} --Tool Name, place the item in a tool in the ServerStorage

GPS = game:GetService("GamePassService")
GPS2 = game:GetService("MarketplaceService")
game:GetService("Players").PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
    if char:FindFirstChild("Humanoid") ~= nil then
        print("Has humanoid")
        if GPS2:UserOwnsGamePassAsync(player.UserId,gpid) then -- this is for the new gamepass gpid, not the old assetid
            for _,v in pairs(tools) do
                if game:GetService("ServerStorage"):FindFirstChild(v) then
                    game:GetService("ServerStorage"):FindFirstChild(v):clone().Parent = player.Backpack
                end
            end

        else
            print("Not awarding item")
        end
    end
end)
end)
0
Thanks man MasonJames136 21 — 5y
Ad

Answer this question