The button (GUI) script doesn’t work when I try to define a player backpack. Look:
(Server script)
local button = script.Parent
local SS = game:GetService("ServerStorage")
button.MouseButton1Click:Connect(function(buy)
local backpack = game.Players.LocalPlayer.Backpack
if backpack then
print("Found player backpack")
end
end)
and then the output is:
Players.UrAnoob991199.PlayerGui.ShopGUI.StrongSwordButton.Script:5: attempt to index nil with 'Backpack'
if this is a localscript you can’t access ServerStorage
and if this is a serverscript you should handle the MouseButton1Click Event on the client instead
local Player = game.Players.LocalPlayer
local button = script.Parent
button.MouseButton1Click:Connect(function()
local backpack = Player:WaitForChild("Backpack")
if backpack then
print("Found Player Backpack")
end
end)