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

Accessing Backpack from Server?

Asked by 9 years ago

I'm trying to access a value inside the Players Backpack via a script from the server:

01function onClick(plr)
02    local find = game.Players.LocalPlayer.Backpack.Player_Inv:FindFirstChild("Lock Pick")
03    if find ~= nil then
04        if find.Amount.Value > 0 then
05            script.Parent:Destroy()
06            find.Amount.Value = find.Amount.Value - 1
07        end
08    end
09end
10 
11script.Parent.ClickDetector.MouseClick:connect(onClick)

Scripts like these have worked in the past, so I'm not sure what the problem is here. Also, there is nothing printed in the output related to this script. Help?

1 answer

Log in to vote
2
Answered by 9 years ago

You can't use

1local find = game.Players.LocalPlayer

from a Script, only LocalScripts.

Remember the plr variable in the function? This is the player who clicked. So instead of using

1local find = game.Players.LocalPlayer.Backpack.Player_Inv:FindFirstChild("Lock Pick")

use

1local find = plr.Backpack.Player_Inv:FindFirstChild("Lock Pick")
Ad

Answer this question