Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can you fix this Inventory/Backpack Limit? (No Error In Output)

There is no error or anything, but when somebody purchases it, it says that the player is under the limit, when they reach over 15 tools, it still says it, could somebody help me.

local price = script.Parent.Parent.Price
local tools = game.ReplicatedStorage:WaitForChild("Tools")
local tool = script.Parent.Parent.ItemName
local player = script.Parent.Parent.Parent.Parent.Parent.Parent
local pack = player:WaitForChild("Backpack"):GetChildren() 
local replicatedstorage = game:GetService("ReplicatedStorage")

     script.Parent.MouseButton1Click:connect(function()
	   if #pack >= 15 then
	            print("This player has to many items")
	            pack:Destroy()
	            replicatedstorage.ClassicSword:Clone()
                     end
	   if #pack <= 15 then
        print("Player Is Under Limit")
       if player.Data:FindFirstChild("Coins").Value >= price.Value then
	   player.Data:FindFirstChild("Coins").Value = player.Data:FindFirstChild("Coins").Value - price.Value
		game.ReplicatedStorage.ShopBuy:FireServer(tool.Value)

  end
 end
end)

This is a LocalScript that functions when somebody clicks the textbutton. There already is a leaderstats and everything. Any possible clue?

1 answer

✓ Accepted answer
local price = script.Parent.Parent.Price
local tools = game.ReplicatedStorage:WaitForChild("Tools")
local tool = script.Parent.Parent.ItemName
local player = game.Players.LocalPlayer
local replicatedstorage = game:GetService("ReplicatedStorage")

     script.Parent.MouseButton1Click:connect(function()
local pack = player:WaitForChild("Backpack"):GetChildren() 
       if #pack >= 15 then
                print("This player has to many items")
                pack:Destroy()
                replicatedstorage.ClassicSword:Clone()
                     else
       if #pack <= 15 then
        print("Player Is Under Limit")
       if player.Data:FindFirstChild("Coins").Value >= price.Value then
       player.Data:FindFirstChild("Coins").Value = player.Data:FindFirstChild("Coins").Value - price.Value
        game.ReplicatedStorage.ShopBuy:FireServer(tool.Value)
end
  end
 end
end)

Try this!

This discussion is preserved as it was. New answers, comments, and votes are closed.