I want to get a tool on a viewport but im not sure how to, can someone help me?
local tool = --define here
local ViewPortFrame
local model = Instance.new("Model", ViewPortFrame)
for i, v in pairs(tool:GetDescendants()) do
if v:IsA("Part") then v.Parent = model end
end
local viewportCamera = Instance.new("Camera")
ViewPortFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = ViewPortFrame
But the tool is in a table
["Epic"] = {
game.ReplicatedStorage.Equipment.EpicArmor;
game.ReplicatedStorage.Equipment.Sword
}
local replicatedstorage = game:GetService("ReplicatedStorage")
local ArmorModule = require(game.ReplicatedStorage:WaitForChild("ArmorHandler"))
local remote = replicatedstorage.Events:WaitForChild("UpdateInventory")
local newRandomArmor = ArmorModule.chooseRandom()
local newArmor = newRandomArmor:Clone()
local DataUpdater = game.ReplicatedStorage.Events:WaitForChild("DataUpdater")
local uis = game:GetService("UserInputService")
local legendVal = math.random(100,195)
local epicval = math.random(25, 80)
local player = game.Players.LocalPlayer
local enterPressed = false
uis.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.Return then
enterPressed = true
end
end)
uis.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.Return then
enterPressed = false
end
end)
replicatedstorage.Events.UpdateInventory.OnClientEvent:Connect(function(player, armor)
local template = script.Parent.MainGui.InventoryHolder.Inventory.Templates.Template
local newTemplate = template:Clone()
newTemplate.Parent = script.Parent.MainGui.InventoryHolder.Inventory.Duplicates
local camera = Instance.new("Camera")
local armorname = newArmor.Name
local template2 = script.Parent.MainGui.Reward.Template
local newTemplate2 = template2:Clone()
newTemplate2.Parent = script.Parent.MainGui.Reward
camera.CFrame = CFrame.new(newArmor.PrimaryPart.Position + (newArmor.PrimaryPart.CFrame.lookVector * 3), newArmor.PrimaryPart.Position)
camera.Parent = newTemplate2.VP
newArmor.Parent = newTemplate2.VP
newTemplate2.VP.CurrentCamera = camera
script.Parent.MainGui.Reward.Visible = true
newTemplate2.Visible = true
wait(2)
script.Parent.MainGui.Reward.Visible = false
newTemplate2.Visible = false
newTemplate.Visible = true
camera.CFrame = CFrame.new(newArmor.PrimaryPart.Position + (newArmor.PrimaryPart.CFrame.lookVector * 3), newArmor.PrimaryPart.Position)
camera.Parent = newTemplate.VP
newArmor.Parent = newTemplate.VP
newTemplate.VP.CurrentCamera = camera
newTemplate:WaitForChild("ArmorName").Value = armorname
newTemplate.Name = armorname
DataUpdater:FireServer(player, armor)
for i, v in pairs(ArmorModule.rarities) do
if table.find(ArmorModule.armors["Legendary"], newRandomArmor) then
newTemplate2.VP.BackgroundColor3 = Color3.fromRGB(153, 134, 13)
newTemplate.VP.BackgroundColor3 = Color3.fromRGB(153, 134, 13)
newTemplate.VP.BorderColor3 = Color3.fromRGB(255, 171, 32)
elseif table.find(ArmorModule.armors["Epic"], newRandomArmor) then
newTemplate2.VP.BackgroundColor3 = Color3.fromRGB(138, 97, 255)
newTemplate.VP.BackgroundColor3 = Color3.fromRGB(128, 43, 255)
newTemplate.VP.BorderColor3 = Color3.fromRGB(168, 102, 253)
end
end
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local X = Mouse.X
local Y = Mouse.Y
local infoTemp = script.Parent.MainGui.InfoTemplate
local newInfo = infoTemp:Clone()
newInfo.Parent = script.Parent.MainGui
newTemplate.MouseEnter:Connect(function()
for i, v in pairs(ArmorModule.rarities) do
if table.find(ArmorModule.armors["Legendary"], newRandomArmor) then
newInfo.Visible = true
newInfo.Template.Text = armorname
newInfo.attack.Text = "Attack: "..legendVal
player:WaitForChild("Data").EquippedValue.Value = legendVal
elseif table.find(ArmorModule.armors["Epic"], newRandomArmor) then
newInfo.Visible = true
newInfo.attack.Text = "Attack: "..epicval
newInfo.Template.Text = armorname
player:WaitForChild("Data").EquippedValue.Value = epicval
end
end
newTemplate.MouseLeave:Connect(function()
newInfo.Visible = false
end)
newTemplate.MouseMoved:Connect(function()
newInfo.Position = UDim2.new(0,Mouse.X,0,Mouse.Y)
end)
end)
end)
To grab the sword from that array it’d be
local swordClone = tableName["Epic"][2]:Clone() -- clone of the sword