Help with equipping script

Hello community, this is a script that when I click “Equip” it has to remove all the “Equipped”, from all the suitcases in my inventory. So I decided to start a “For i,v in pairs”, to make invisible the other equipped but I get an error. My point is that I don’t want Equipped to be shown twice or more times on the backpacks.

LocalScript: In Equip

script.Parent.MouseButton1Click:Connect(function()
	local Player = game.Players.LocalPlayer
	local Info = Player.PlayerGui.Shops.Island1.BagsShop.Info
	local Cost = 25
	game.ReplicatedStorage.Compras.Bags.Bag1.Equip:FireServer(Cost)
	for i,v in pairs(Info:GetChildren()) do
		v.Equipped.Visible = false
	end
	script.Parent.Visible = false
	script.Parent.Parent.Equipped.Visible = true
end)

LocalScript: In Equipped:

script.Parent.MouseButton1Click:Connect(function()
	local Player = game.Players.LocalPlayer
	if Player.Bag.Amount.Value > 0 then
		Player.PlayerGui.Advertencias.SellBag.Visible = true
		wait(2.5)
		Player.PlayerGui.Advertencias.SellBag.Visible = false
	elseif Player.Bag.Amount.Value == 0 then
		local Cost = 0
		game.ReplicatedStorage.Compras.Bags.Bag1.Equipped:FireServer(Cost)
		script.Parent.Visible = false
		script.Parent.Parent.Equip.Visible = true
	end
end)

Image:

Screenshot_64

The error is in the LocalScript of In “Equip”.

Are you saying you only want to have 1 tool in you’re backpack only? And what’s you’re error?

I already put the image of the error in the notice bro

I don’t understand, What’re you trying to do?. Are you trying to make it so there is only 1 Tool in you’re backpack??

Oh no no, what I want is to make not visible the other “Equipped”, because if I equip a suitcase, I can equip another one, that’s the mistake.

1 Like

Can you show me Info please?..

In short, when I equip a backpack, I get “Equipped”, but when I go to equip another backpack I get “Equipped”, but the “Equipped” of the other backpack does not become invisible. And both backpacks would say “Equipped”. And that’s what I don’t want to do.

The error is happening because the current object you’re iterating through does not have an instanced called Equipped, make a check to see if it exists and then make it invisible

script.Parent.MouseButton1Click:Connect(function()
	local Player = game.Players.LocalPlayer
	local Info = Player.PlayerGui.Shops.Island1.BagsShop.Info
	local Cost = 25
	game.ReplicatedStorage.Compras.Bags.Bag1.Equip:FireServer(Cost)
	for i,v in pairs(Info:GetChildren()) do
		if not v:FindFirstChild("Equipped") then continue end
		v.Equipped.Visible = false
	end
	script.Parent.Visible = false
	script.Parent.Parent.Equipped.Visible = true
end)

I think it’s ok, but now I don’t see the “Equip”, what can I do?

Hmm, which code makes Equip visible/invisible?

visible, :slight_smile: is best

No I mean, which code block you sent is the one that handles making it visible? Also what’s in that RemoteEvent?

In this remote event you change the value of the backpack

Add this code to make the others visible

script.Parent.MouseButton1Click:Connect(function()
	local Player = game.Players.LocalPlayer
	local Info = Player.PlayerGui.Shops.Island1.BagsShop.Info
	local Cost = 25
	game.ReplicatedStorage.Compras.Bags.Bag1.Equip:FireServer(Cost)
	for i,v in pairs(Info:GetChildren()) do
		if not v:FindFirstChild("Equipped") and v:FindFirstChild("Equip")then continue end
		v.Equipped.Visible = false
		v.Equip.Visible = true
	end
	script.Parent.Visible = false
	script.Parent.Parent.Equipped.Visible = true
end)

The guard clause should be

if not v:FindFirstChild("Equipped") and not v:FindFirstChild("Equip") then continue end

So if it neither has Equipped nor Equip, don’t do anything

1 Like