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

How to give a tool with the new gamepass system?

Asked by 5 years ago
Edited 5 years ago

I tried this:

-- In workspace normalscript
local MpS = game:GetService"MarketplaceService"
local gamepass = 4775497
local tool = {"Glock 18"}

workspace.ChildAdded:connect(function(plr)
    local player = game.Players:FindFirstChild(plr.Name)
    local backpack = player:WaitForChild("Backpack")
    if MpS:UserOwnsGamePassAsync(player.UserId, gamepass) then
        game.ServerStorage:FindFirstChild(tool):Clone().Parent = backpack
    end
end)

i know this is a bad way but i tried something...

0
Why are you using Lighting as storage? User#19524 175 — 5y
0
I am using ServerStorage but that was for something else a test MaxDev_BE 55 — 5y

1 answer

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

You shouldn’t be using Lighting as storage, as this is deprecated and not supported by ROBLOX. Move the tool to ReplicatedStorage for client and server access. Move to ServerStorage for server only access. Your problem is on lines 4 and lines 10, you’re trying to find a table in Lighting. Index the item in the table.

local MpS = game:GetService"MarketplaceService
local gamepass = 4775497
local tool = {"Glock 18"}

game:GetService("Players").PlayerAdded:Connect(function(plr)
    if Mps:UserOwnsGamePassAsync(plr.UserId, gamepass) then
        if game:GetService("ServerStorage"):FindFirstChild(tool[1]) then
            local clone = game:GetService("ServerStorage")[tool[1]]:Clone()
            clone.Parent = player.StarterGear
            clone:Clone().Parent = player.Backpack
        end
    end
end)

On a side note, switch to Connect, as ROBLOX may remove connect in the future.

Ad

Answer this question