Player.Backpack suddenly not working at all?

I’m not sure what went wrong, backpack suddenly stopped working at all? There were no changes to my script, but now loading player inventories became completely broken?

Shows raycast hitbox which indicates that the tool was loaded, but it’s not in the player’s backpack? Is anyone else facing this issue?

3 Likes

Code for the equipping tool part. I’m not sure why but it says that the parent of newweapon is backpack but it doesn’t appear in the backpack of the player?

for i, tool in ipairs(Weapons:GetChildren()) do
	local stool = tostring(tool)
	tool:FindFirstChild(stool).ProximityPrompt.Triggered:Connect(function(player)
		if not player.Backpack:FindFirstChild(stool) and not player.Character:FindFirstChild(stool) then	
			if player.weapons:FindFirstChild(stool) then
				local newweapon = game.ReplicatedStorage.Weapons:FindFirstChild(stool):Clone()
				player.weapons:FindFirstChild(stool).Equipped.Value = true
				newweapon.Parent = player.Backpack
				
				for i,weap in pairs(player.weapons:GetChildren()) do
					if weap.Equipped.Value then
						local currentweapon = tostring(weap)
						if player.Backpack:FindFirstChild(currentweapon) then
							player.Backpack:FindFirstChild(currentweapon):Destroy()
						end

						if player.Character:FindFirstChild(currentweapon) then
							player.Character:FindFirstChild(currentweapon):Destroy()
						end

						weap.Equipped.Value = false
						continue
					end
				end
			end
		else
			-- already equipped; nothing will happen
			
		end
	end)
end
1 Like

ipairs usually don’t work for getchildren

for object with directories, you want to use ‘pair’ instead

1 Like

using pairs as you’ve suggested didnt fix anything

1 Like

so the way you are storing the tools in the player.weapons is bad coding as-well this might cause issue you want items that a replicated stored in replicated storage

1 Like

im not storing the tools in player.weapons; im storing the data in there. so that the tools are then loaded in the backpack

1 Like

so I belive the correct way to do it is you store data within the tool and then the models you request from replicatedstorage if that what youre doing

1 Like

turns out the issue was that the hierachy of the first block and second block was wrong; and it should have been the for loop first. whats weird was that the code was completely fine initially and just broke all of a sudden for that reason; roblox is tripping

1 Like

yeah it was for the ipair error i deserve a solution xdd

2 Likes

it wasnt the ipair error because there was nothing wrong with tha, it was regarding the code under the if not player.Backpack…

the first if statement and the for loop after should have been switched around; because when the player is given the weapon, and the equipped value is true; the for loop then checks for the equipped.value and deletes the weapon which means that the changed weapon is removed. ill still give u a like though

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.