Adding Weapons Help!

So I am making a game the has weapons and is the best way to give a player a sword by adding it to there backpack. What if they have many swords, I only want them to have one equipped at a time and I also don’t want it to show at the bottom.

Right now this what the sword has:
image

This is what I want to happen:


As you can see I want it so the wooden sword doesn’t show up at the bottom, and inside the inventory instead, I’m not sure how to go about this, unless it doesn’t go in the backpack?

So what I want to know is, how would I equip a weapon without it showing in the hotbar, and in the inventory itself? It should remain in your hand until you either replace it with another or unequip it.

So when a player has the sword, would it clone the tool, add it into a viewport frame, and when equipped where would it go. I’m not sure, If i was a bit vague of what to do please ask, I don’t want a whole script just maybe a guide of what I should do. Currently I have an idea but not sure how to execute.

Have you tried turning off core GUI in a local script to turn off the players backpack GUI in ROBLOX?

local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

Try inserting it into StarterPlayerScripts.

That doesn’t get rid off the backpackGui, not sure why.

Oh? The tool still goes into your backpack but the GUI isn’t there.

I’ve only scripted it right now to go to backpack, so if it was in the inventory and I click it, it will add it to players Backpack. Not sure how to do add the tool to a viewport. I know how to clone it, but the not sure how to do the camera.

You want a image representation of the item itself using viewport frames?

Yeah, but not sure how to make the camera position.

add.AddedEvent = function(item, class) -- Starting the game and gaining something like a sword  (class - Weapon/Potion/Armour)
	local ReplicatedFirst = game:GetService("ReplicatedFirst")
	local items = ReplicatedFirst.class:GetChildren()
	for i, v in pairs(items) do
		if v.Name == item then
			local item = v:Clone() -- Cloning the potion.
			-- Need to create a camera, is positioned away from the potion and parent it to a viewport
			-- Need to make the ui for item
			
		end
	end
end

This is what I currently have, I need to change it a bit but yeah this the concept.

Create the viewport frame then, create a camera and parent it to the viewport frame.
viewportCamera.Parent = viewportFrame

But would it see the weapon, I thought it would be something to do with the camera position.

If you are familiar with CFrames:
local viewportCamera = Instance.new(“Camera”) – Creating camera
viewportFrame.CurrentCamera = viewportCamera – Setting the created viewportFrame.CurrentCamera to the new camera made.
viewportCamera.Parent = viewportFrame – Making the parent of the camera the viewport frame.
viewportCamera.CFrame = CFrame.new(Vector3.new(position), (object).Position) – the new camera is positioned relative to the “object” or whatever you want by resetting its CFrame

Take in note the last part is where you can set the viewportCamera CFrame to whatever position you would like for the camera to be.

But this isn’t necessarily easy handling viewport frames, try using this api reference if your having more problems: Frames | Documentation - Roblox Creator Hub

viewportCamera.CFrame = CFrame.new(Vector3.new(position), (object).Position)

What would the position in brackets be? 0, 0, 0?

Position in the UI viewport frame where you want the weapon to be displayed if that make sense.

add.AddedEvent = function(item, class, player) -- Starting the game and gaining something like a sword  (class - Weapon/Potion/Armour)
	local ReplicatedFirst = game:GetService("ReplicatedFirst")
	local items = ReplicatedFirst.class:GetChildren()
	for i, v in pairs(items) do
		if v.Name == item then
			for num, rarity in pairs(script.Rarities:GetChildren()) do
				if v.Rarity.Value == rarity.Name then
					local rare = rarity:Clone()	-- Clone the rarity ui
					local clone = v:Clone() -- Cloning the tool
					clone.Parent = rare.ItemView -- Setting the tool to the viewportFrame
					local Camera = Instance.new("Camera") -- Creating a Camera
					rare.ItemView.CurrentCamera = Camera -- Setting the viewports CurrentCamera to the new one
					Camera.Parent = rare.ItemView -- The camera parent is the viewportFrame
					Camera.CFrame = CFrame.new(Vector3.new(0,0,0), v.Position) -- Position of the camera
				end
			end	
		end
	end
end

This is what I currently have setup for adding it to the players inventory, I added some comment to make sure it can be read easily. I just need to make the UI parented to the players inventory.

and I don’t quite get that positioning, so what would centred be. 0, 5, 0

Alright, are you getting any errors or anything that it isn’t working properly?

I haven’ tested it yet, I still need to finish of the script.

Alright get back to me if your having problems, have fun scripting.

There’s no errors but it doesn’t get added to my inventory.

Here’s the code:
Datastore:

for num, item in pairs(ReplicatedFirst.Weapons:GetChildren()) do  -- Checks all the weapons in the weapons folder
	for serial, name in pairs(Weapons.WeaponsTable) do -- Checks table
		if item.Name == name["Name"] and name["Owned"] == true then -- if they own it
			adding.AddedEvent(item, "Weapons", player)
		end
	end
end

Module Script:

add.AddedEvent = function(item, class, player) -- Starting the game and gaining something like a sword  (class - Weapon/Potion/Armour)
	local ReplicatedFirst = game:GetService("ReplicatedFirst")
	local items = ReplicatedFirst[class]:GetChildren()
	for i, v in pairs(items) do
		if v.Name == item then
			for num, rarity in pairs(script.Rarities:GetChildren()) do
				if v.Rarity.Value == rarity.Name then
					local rare = rarity:Clone()	-- Clone the rarity ui
					local clone = v:Clone() -- Cloning the tool
					clone.Parent = rare.ItemView -- Setting the tool to the viewportFrame
					local Camera = Instance.new("Camera") -- Creating a Camera
					rare.ItemView.CurrentCamera = Camera -- Setting the viewports CurrentCamera to the new one
					Camera.Parent = rare.ItemView -- The camera parent is the viewportFrame
					Camera.CFrame = CFrame.new(Vector3.new(0,0,0), v.Position) -- Position of the camera
					rare.Parent = player.PlayerGui.Inventory.Inventory.class.."Inv"
				end
			end	
		end
	end
end

Are you parenting the tool to the players backpack?