Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Accessing Backpack from Server?

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

function onClick(plr)
	local find = game.Players.LocalPlayer.Backpack.Player_Inv:FindFirstChild("Lock Pick")
	if find ~= nil then
		if find.Amount.Value > 0 then
			script.Parent:Destroy()
			find.Amount.Value = find.Amount.Value - 1
		end
	end
end

script.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

✓ Accepted answer

You can't use

local 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

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

use

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

This discussion is preserved as it was. New answers, comments, and votes are closed.