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

using findFirstChild in Player's Backpack?

Asked by
KenzaXI 166
8 years ago

Hi, as the Title sais I'm trying to locate 2 tools which are both called "atlas sword" using findFirstChild method. but for some reason it won't work. here's the script:

local player = game.Players.LocalPlayer 
local l = player.Backpack:findFirstChild("atlas sword") 
script.Parent.MouseButton1Click:connect(function()
    if game:GetService("MarketplaceService"):PlayerOwnsAsset(player,277976767) then
        game.Lighting["atlas sword"]:Clone().Parent = player.Backpack
    if l then
    l:Remove()
end
    end
end)



Thanks for the Help.

1 answer

Log in to vote
0
Answered by 8 years ago

You were making it remove the tool right after it gave the player it, also not sure why the local l = player.Backpack:findFirstChild("atlas sword") won't work, but here's a script that'll work for what you want. Sorry I can't explain it any better.

local player = game.Players.LocalPlayer 

script.Parent.MouseButton1Click:connect(function()
    if player.Backpack:FindFirstChild("atlas sword") then
        player.Backpack["atlas sword"]:Remove()
end
    if game:GetService("MarketplaceService"):PlayerOwnsAsset(player,277976767) then
        game.Lighting["atlas sword"]:Clone().Parent = player.Backpack
    end
end)

0
Cheers KenzaXI 166 — 8y
Ad

Answer this question