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.
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.
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.
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.
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.
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
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