So I am working on a backpack/inventory system for my game but this script appears to not be working. It works on studio, but doesn't in the actual game. Here is the script and if you need more information, let me know! Thank you!

local Items = {}
local frames = {}
local Equiped = nil
local Player = game.Players.LocalPlayer
local character = Player.Character

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)

function Scan(location)
	for i,v in pairs(location:GetChildren()) do
		if v:IsA("Tool") or v:IsA("HopperBin") then
			table.insert(Items,v)
		end
	end
end

Scan(character)
Scan(Player.Backpack)


function Update()
	print(Equiped)
	for i,v in pairs(frames) do
		v:Destroy()
	end
	for i,v in pairs(Items) do
		local sam = script.Sample:Clone()
		sam.Name = v.Name
		sam.Parent = script.Parent.Holder
		sam.ImageLabel.Image = v.TextureId
		sam.Text = v.Name
		table.insert(frames,sam)
		if Equiped ~= nil and Equiped == v then
			sam.BorderSizePixel = 2
		end
		sam.MouseButton1Click:connect(function()
			if Equiped == nil or Equiped ~= v then
				Equiped = v
				character.Humanoid:UnequipTools()
				character.Humanoid:EquipTool(v)
			else
				Equiped = nil
				character.Humanoid:UnequipTools()
			end
		end)
	end
end

function backpackchanged()
	Items = {}
	Scan(character)
	Scan(Player.Backpack)
	Update()
end

backpackchanged()

Player.Backpack.ChildAdded:connect(backpackchanged)
Player.Backpack.ChildRemoved:connect(backpackchanged)

character.ChildAdded:connect(backpackchanged)
character.ChildRemoved:connect(backpackchanged)

12 comments

0

Where is this script located in your game?

0

The script is a localscript inside a ScreenGUI and inside this script is a Textbutton. There is a Frame inside the ScreenGui as well

0

Is the screen GUI in the StarterGUI or elsewhere?

0

Yes, the ScreenGui is in the StarterGui

0

I'm not very experienced with this but in Line 7, change that to script.Parent.Parent:SetCoreGuiEnabled......... etc. Or set a variable as script.Parent.Parent and use variable:SetCore......... etc. Also did you get any errors in the console when running this?

0

If that worked, I'll explain what happened.

0

Ok i did that and in studio. no error. But in game, I get this error Sample is not a valid member of LocalScript. Sample is inside the localscript btw

0

Sorry. Like I said, I'm not as experienced. Hopefully someone else can help you.

0

Ok thank you so much for trying.

0

Tell me the errpr message and i can figure it out

0

Sample is not a valid member of local script. Sample is inside the local script

0

Line 11 change to if v:IsA("BackpackItem") then