The title speaks for itself
How would I make a player backpack? with a capacity count?
The title speaks for itself
How would I make a player backpack? with a capacity count?
This is tough, do you want it like if there are too many tools in the Roblox backpack the player will equip the tool it tried to store in their backpack?
OMG
Thats my fault, sorry. I meant backpack like bee swarm backpacks if you know what they are.
CurrentCapacity/MaxCapacity
returns a value between 0 and 1 which can be used to scale the frame
.
If a player touched an object, how would I make the game make it so that the player gets 1+ of their Current Capacity? How would I know/detect what player was it that equipped it?
and also, is there a way I can attach this to a player if they click a equip button?
How would I save the players backpack capacity and what type of backpack they have?
You can google how to do those things. I’m pretty sure the api covers most of your questions.
You can store every player in a list when they join. Make a local script and check if the objects were touched by the local player. If so, fire a remote event to the server and increase the value in the list by 1. Attach the touched objects by making a RigidConstraint if they trigger a ProximityPrompt. To save backpacks, use the DataStoreService.
For your first question, you can store an IntValue inside the player (Which you might also use for datastore), and increment it whenever the player touched it.
You don’t need to detect what player equipped it. You can simply do something like this. If you are storing the touchable parts in a model or folder you can just put this script in the model/folder.
local Players = game:GetService('Players')
local Folder = script.Parent
for i, Part in pairs(Folder:GetChildren()) do
Part.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild('HumanoidRootPart') then
local Character = Hit.Parent
local Player = Players:GetPlayerFromCharacter(Character)
local CurrentCapacity = Player.CurrentCapacity --// the int value inside the player
local Backpack = Character:FindFirstChild('Backpack')
local MaxCapacity = Backpack.MaxCapacity --// int value in the backpack
if CurrentCapacity.Value < MaxCapacity.Value then
CurrentCapacity.Value = CurrentCapacity.Value + 1
end
end
end
end
To attach it to a player, just have an invisible part (green in my example) that tells you where the backpack should be relative to the player, make it the primary part, then whenever you need to, do Backpack:SetPrimaryPartCFrame()
and then put in the CFrame of the HumanoidRootPart. After that you can create a weld between the backpack root part and the humanoidrootpart using weldconstraint.
If you’re wondering what the Weld script is, it’s just a script that welds everything in the folder/model to the Root.Value, to make it just paste in the code below and add an ObjectValue called Root.
local Folder = script.Parent
local Root = script.Root.Value
for i, Instance_ in pairs(Folder:GetChildren()) do
if Instance_:IsA('BasePart') then
local Weld = Instance.new('WeldConstraint', Instance_)
Weld.Part0 = Instance_
Weld.Part1 = Root
end
end
what do you mean by relative to the player? do you mean like were the backpack is going to be like on the back of the players Torso?
I meant relative to the HumanoidRootPart
What is the folder for in the Weld script and this script?
It doesn’t have to be a folder, just set the ObjectValue called “Root” to RootPart
game.Players.PlayerAdded:Connect(function(Player)
Player.Backpack.ChildAdded:Connect(function()
print(#Player.Backpack:GetChildren()) -- Value
end)
Player.Backpack.ChildRemoved:Connect(function()
print(#Player.Backpack:GetChildren()) -- Value
end)
end)
And for the other script you just have to put it in the model/folder of objects you want to touch
He doesn’t mean Player.Backpack, he’s talking about the ones used in Bee Swarm Simulator
Im not following, would RootPart be HumanoidRootPart? Or the Primary Part of the Backpack
It would be the primary part of the backpack
Okay lets start from making the backpack first, let me change the script so you don’t need the ObjectValue anymore.
local Model = script.Parent
local Root = Model.RootPart
for i, Instance_ in pairs(Model:GetChildren()) do
if Instance_:IsA('BasePart') then
local Weld = Instance.new('WeldConstraint', Instance_)
Weld.Part0 = Instance_
Weld.Part1 = Root
end
end
Bad idea, exploiters can easily spam the remote and get infinite currency. You need to check the touched event on the server.