Equip and unequip inventory system for round system

Hello, so I am struggling to find tutorials on how to do this

I am trying to get an inventory system for my game, it is basically a scrolling screen of items that the player can select, they can only equip one, then, when the round starts, it gets that tool and puts it in their backpack

Keep in mind that my tiny brain cant script, so keep things simple

You can even recommend models or tutorials, anything helps

If you can help, you are a legend

2 Likes

Thatā€™s the exact same problem as me lol, unfortunately I do not know as well

1 Like

Oh, some extra stuff

Items equipped are sent to ServerStorage
When one item is equipped, the previous equipped item is no longer in ServerStorage, so one item in server storage at a time

Duplicate items are put as just one but with a x2 at the top

So, Iā€™m a little confused myself here with what you are trying to do but Iā€™m going to assume what I picked up and you can correct me later on if need be;

Assuming you have the tools stored inside of a folder specific to each player;

When the round starts simply run through each of the folders inside of ServerStorage where you have these kept with for i, v in pairs loop

Example:

for _, player in pairs(game:GetService('Players'):GetPlayers()) do --// Getting each of the players
	if player:IsA('Player') then --// Making sure each player instance is actually a player
		for _, folder in pairs(game:GetService('ServerStorage'):FindFirstChild('YOUR_TOOL_HOLDING_FOLDERS', true):GetChildren()) do --// Get all of the folders, replace the second string with your folder
			if folder:IsA('Folder') then --// Making sure that folder is a folder
				if string.lower(tostring(folder.Name)) == string.lower(tostring(player.Name)) then --// Converting both player name and folder name to lowercase and checking if they are the same
					for _, tool in pairs(folder:GetChildren()) do --// Getting each tool in the folder
						if tool:IsA('Tool') then --// Making sure that the tool is a tool
							if player:FindFirstChild('Backpack', false) then --// Finding the players backpack
								local tool_clone = tool:Clone().Parent == player:FindFirstChild('Backpack', false) --// Cloning the tool and setting the parent to the players backpack
							end;
						end;
					end;
				end;
			end;
		end;
	end;
end;

--// Side note the Semi-Colons ';' mean nothing in lua and it's just a habit of mine, you do NOT need them for this to work.

Assuming you donā€™t have the tools stored inside of a folder specific to each player;

Inside of your initial script you will need to create a folder pertaining to each person for when they select the tool, if there is already a folder just remove the old tool and replace it with the new tool. If there isnā€™t just create a folder inside of your script and then parent the tool clone to it.

Example:

if game:GetService('ServerStorage'):FindFirstChild('YOUR_HOLDING_FOLDERS', true):FindFirstChild(plr.Name) then
	
	local folder = game:GetService('ServerStorage'):FindFirstChild('YOUR_HOLDING_FOLDERS', true):FindFirstChild(plr.Name)
	
	if folder:FindFirstChildOfClass('Tool') then
		folder:FindFirstChildOfClass('Tool'):Destroy()
		local tool_clone = ('HOWEVER YOU PARENT YOUR TOOLS'):Clone().Parent == folder
	end
	
else
	local player_folder = Instance.new('Folder').Parent == game:GetService('ServerStorage'):FindFirstChild('YOUR_HOLDING_FOLDERS', true)
	local tool_clone = ('HOWEVER YOU PARENT YOUR TOOLS'):Clone().Parent == player_folder
	
end;

--// Then this is how you would give the players their tools in game

for _, player in pairs(game:GetService('Players'):GetPlayers()) do --// Getting each of the players
	if player:IsA('Player') then --// Making sure each player instance is actually a player
		for _, folder in pairs(game:GetService('ServerStorage'):FindFirstChild('YOUR_TOOL_HOLDING_FOLDERS', true):GetChildren()) do --// Get all of the folders, replace the second string with your folder
			if folder:IsA('Folder') then --// Making sure that folder is a folder
				if string.lower(tostring(folder.Name)) == string.lower(tostring(player.Name)) then --// Converting both player name and folder name to lowercase and checking if they are the same
					for _, tool in pairs(folder:GetChildren()) do --// Getting each tool in the folder
						if tool:IsA('Tool') then --// Making sure that the tool is a tool
							if player:FindFirstChild('Backpack', false) then --// Finding the players backpack
								local tool_clone = tool:Clone().Parent == player:FindFirstChild('Backpack', false) --// Cloning the tool and setting the parent to the players backpack
							end;
						end;
					end;
				end;
			end;
		end;
	end;
end;

The main code I provided would be ran AFTER the game is starting

2 Likes

what do you mean by ā€˜however you parent your toolsā€™, do you mean the folder where the tools stay or the server storage?

1 Like

He means wherever the location of the tools are to be cloned from.

sorry to annoy you but I still donā€™t understand lol

Thanks for the help, you are a legend

So, does this take one tool from the folder, or all the tools from the folder, sorry if this is a stupid question

I got this
local players = game:GetService(ā€œPlayersā€)

local length = 60

local PlrsAlive = {}

players.PlayerAdded:Connect(function(plr)
plr:LoadCharacter()
end)

while true do

repeat wait(1) until players.NumPlayers >= 2

wait(30)



local Maps = game:GetService("ServerStorage").Maps:GetChildren()

local ChosenMap = Maps[math.random(1,#Maps)]

map = ChosenMap:Clone()
map.Parent = workspace


local spawns = map:FindFirstChild("Spawns"):GetChildren()

for i, player in pairs(players:GetChildren()) do
	if player.character then
		char = player.character
		
		char:FindFirstChild("HumanoidRootPart").CFrame = spawns[i].CFrame + Vector3.new(0,10,0)
		
		local tag = Instance.new("BoolValue",char)
		tag.Name = "PlayerAlive"
		
		table.insert(PlrsAlive, player)
	end  
end

if game:GetService('ServerStorage'):FindFirstChild('YOUR_HOLDING_FOLDERS', true):FindFirstChild(plr.Name) then

	local folder = game:GetService('ServerStorage'):FindFirstChild('YOUR_HOLDING_FOLDERS', true):FindFirstChild(plr.Name)

	if folder:FindFirstChildOfClass('Tool') then
		folder:FindFirstChildOfClass('Tool'):Destroy()
		local tool_clone = ('HOWEVER YOU PARENT YOUR TOOLS'):Clone().Parent == folder
	end

else
	local player_folder = Instance.new('Folder').Parent == game:GetService('ServerStorage'):FindFirstChild('YOUR_HOLDING_FOLDERS', true)
	local tool_clone = ('HOWEVER YOU PARENT YOUR TOOLS'):Clone().Parent == player_folder

end;

--// Then this is how you would give the players their tools in game

for _, player in pairs(game:GetService('Players'):GetPlayers()) do --// Getting each of the players
	if player:IsA('Player') then --// Making sure each player instance is actually a player
		for _, folder in pairs(game:GetService('ServerStorage'):FindFirstChild('YOUR_TOOL_HOLDING_FOLDERS', true):GetChildren()) do --// Get all of the folders, replace the second string with your folder
			if folder:IsA('Folder') then --// Making sure that folder is a folder
				if string.lower(tostring(folder.Name)) == string.lower(tostring(player.Name)) then --// Converting both player name and folder name to lowercase and checking if they are the same
					for _, tool in pairs(folder:GetChildren()) do --// Getting each tool in the folder
						if tool:IsA('Tool') then --// Making sure that the tool is a tool
							if player:FindFirstChild('Backpack', false) then --// Finding the players backpack
								local tool_clone = tool:Clone().Parent == player:FindFirstChild('Backpack', false) --// Cloning the tool and setting the parent to the players backpack
							end;
						end;
					end;
				end;
			end;
		end;
	end;
end;

for i = 0, length do
	wait(1)
	for x, player in pairs(players:GetChildren()) do
		if player then 
			if player.Character then
				if not player.Character:FindFirstChild("PlayerAlive") then
					table.remove(PlrsAlive, x)
				end
			end
		else
			table.remove(PlrsAlive, x)
		end
	end
	if #PlrsAlive < 2 then break end		
end



for i, player in pairs(players:GetChildren()) do
	
	for i, tool in pairs(player.Backpack:GetChildren()) do
		tool:Destroy()
	end
	
	if player.Character:FindFirstChild("PlayerAlive") then
		player.Character:FindFirstChild("PlayerAlive"):Destroy()
	end
	player:LoadCharacter()
end		
map:Destroy()

end

is this correct

i just pasted it in to see if its correct

the script is probably correct, how about go test it out and see if it works

1 Like

like, if you took a sword tool and put it in workspace, the sword is parented to workspace

oh ok thanks for your confirmation

ok, I tried it, it actually didnt work, so forget what I said, putting Worspace or serverstorage doesnt work

oh ok then, any updates about the script?

well, not really, I replaced some code with that and it just spawns me without tools, I think I might make another topic, more on the inventory, because this is kinda confusing

I recommend you should see alvinbloxā€™s playlist called ā€˜ how to make a gameā€™, in the last part of the playlist it covers on how to do shop and the equip system, you should go check it out

1 Like

it takes all of the tools from each of the players folders

Thanks, I think I will make another topic tmr about an easier way to do this

But, I have learned something here, thank you for explaining the script

So I will mark this as the end :+1:

You should mark the actual solution as the solutionā€¦

You mean NavalFiā€™s solution

Thanks for telling me :sweat_smile:

Ok I made a new topic