How do i made a weight inventory system like isle?

Hello there! Thank you for being here!

I’m currently looking for a way to create a weight system in the inventory similar to the one used in “Isle”.

How does it work?

Essentially, each tool is assigned a specific weight, and the player’s inventory has a limit on how much they can carry. For instance, if the player’s weight limit is set to 5, they can only carry tools that collectively weigh up to 5.

What I’m particularly interested in is implementing a GUI that displays how much weight the player is carrying and how much they can support.

Any assistance is greatly appreciated! Your input on these forums always goes a long way in helping others!

5 Likes

add an attribute to every tool named “Weight” and change the value accordingly
inside a script in the serverscriptservice:

local maxWeight = 5 --variable (optional change)
local currentWeight = 0 --variable to track current weight

local co = nil --variable for future coroutines

function playerAdded(player) --function to handle player joining
   repeat task.wait() until player:FindFirstChild("Backpack") ~= nil and player:FindFirstChild("PlayerGui") ~= nil --wait until the backpack and gui are loaded to avoid errors
   local backpack = player.Backpack
   local weightCounter = pathtocounterguitextlabel --e.g player.PlayerGui.WeightCounter.TextLabel
   function updateGui()
      weightCounter.Text = string.format("[%d/%d]", currentWeight, maxWeight) --e.g "[1/5]"
   end

   function updateCurrent()
      currentWeight = 0 --reset counter
      if #backpack:GetChildren() == 0 then return end --no items? leave it at 0
      for _, v in backpack:GetChildren() do --loop through items
         if not v:IsA("Tool") then continue end --skip to the next child if it is not a tool
         currentWeight += v:GetAttribute("Weight")
      end
      updateGui() --keep the gui up to date
   end

   function changeText(text) --change gui text to "Too Heavy!"
      weightCounter.Text = text
      task.wait(1.35)
      updateGui() --set back to [currentWeight/maxWeight]
   end

   backpack.ChildAdded:Connect(function(tool) --when something is added to backpack
      if co then coroutine.yield(co) coroutine.close(co) co = nil updateGui() end --delete co if it is not nil
      if not tool:IsA("Tool") then return end --leave this whole event if item isnt a tool
      if currentWeight + tool:GetAttribute("Weight") > maxWeight then --if too heavy
         co = coroutine.wrap(changeText) --create a new coroutine so that it doesnt pause script and allows to cancel at any time
         co("Too Heavy!") --change text to "Too Heavy!" for 1.35 seconds
         tool.Parent = workspace --remove the tool from the player's backpack
         return
      end
      updateCurrent()
   end)
end

for _, v in game:GetService("Players"):GetPlayers() do --fire function for players that join before the .PlayerAdded event gets connected
   playerAdded(v)
end

game:GetService("Players").PlayerAdded:Connect(playerAdded) --connect the function

note that this is just a base, you will have to make necessary modifications and additions to fit your system

4 Likes
--your inventory weights are here:
local weights = {
,tool1={weight=1}
,tool2={weight=2}
,tool3={weight=2}
}
--in the script to detect weight,
local totalweight=0
for _,toolobject in weights do
local toolweight=toolobject.weight
totalweight+=toolweight
end
if toolweight>5 then
--nope cant carry
end
3 Likes

Firstly, I’m having trouble comprehending line 6 and what action needs to be taken with it. While the mathematical aspect isn’t overly complex, the challenge lies in identifying tools with weight and those without, then devising individual implementations for each. This task is far from straightforward.

3 Likes

I know it is a base, but it is very incomplete to what had been said.

2 Likes

I see. You can make it a GUI by displaying the totalweight.

There’s no real non-base solution as there’s not enough details specified. You haven’t particularly defined how to prevent players from holding tools with a weight greater than their limit. We also don’t know how your tools work. Are they viewmodel instances, objects or actual Tool instances? Are the tools defined once you spawn in or do we need to implement something where it is possible for the code to run more than once the character is spawned?

Line 6 is:

You need to put the path to your text label.

2 Likes

Basically I’m trying to make the same system that the roblox game called isle has.

Here I leave you a video, I practically don’t know how to demonstrate it to you in another way.

If the object weighs more or the weight reaches a limit, it will not let you take more objects.

3 Likes

I’ve updated the script and hopefully satisfies some of your missing needs

1 Like

this can be bypassed by exploiters if they change the Weight value. instead you could check the weight (either intvalue or stored in some modulescript) on the server and return a tuple (success: boolean, message: string?) for the localscript to know

3 Likes

Is more easy with values, i think.

1 Like

thats alright, I have made it more secure by making it fully server sided, let me make some few adjustments and ill edit this message when its ready

the edit has been made
now it is fully server sided and more secure to hacks

(unless it’s server sided hacks :/)

2 Likes

Why don’t you directly make an article in the library with instructions?

2 Likes

i don’t think values should be used. attributes are def much better. just collect the amount of weight using attributes from each tool and turn it into one variable.

2 Likes

what do you mean by that?
anyway, it’s been simplified down to the point you only need to modify the ‘weightCounter’ variable and the modulescript

also for any advanced scripters, do lmk if something can be improved

2 Likes

use attributes (i seriously think character limits should be removed)

2 Likes

there’s nothing wrong with using a modulescript

2 Likes

there’s also nothing wrong with using attributes
one simple name change and the item does not have weight applied

2 Likes

(sigh) i will edit it again i guess

3 Likes

alway include a screenshot because we dont play all games.

2 Likes

Above there is a video where I show the example in that game

2 Likes