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?
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
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
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
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