How do i check if something like a model is in a viewport, like getting it if there is a model. Do i do FindFirstChildOfClass? And then how would i clone it?
local newArmor = children.VP. --How do i get that model inside?
How do i check if something like a model is in a viewport, like getting it if there is a model. Do i do FindFirstChildOfClass? And then how would i clone it?
local newArmor = children.VP. --How do i get that model inside?
Yes, FindFirstChildOfClass
can be utilized to find an Instance with a certain ClassName. Similarly, the FindFirstChildWhichIsA
method can be used for class inheritance/if an Instance falls under other categories (e.g. “Parts”, “TrussParts”, “MeshParts”, and “WedgeParts” are all considered BaseParts
).
Example:
local itemCheck = workspace.Part:FindFirstChildOfClass("Model")
if itemCheck then
local clone = itemCheck:Clone() -- Creates a clone of the model that was found
end
Im trying that but it’s not working, it’s not printing ok
if itemCheck then
local newArmor = itemCheck:Clone()
newchild.Parent = PlayerGui:WaitForChild("MainGui").SellFrame.Duplicates
newArmor.Parent = newchild.VP
newchild.Visible = true
print("OK")
If no errors are occurring, chances are a model wasn’t found inside of the Instance. You could introduce alternative conditions to see if that was the case.
Remember that this will only be looking for a child of the Instance and not all of its descendants; a loop would be more ideal for that use case.
local itemCheck = workspace.Part:FindFirstChildOfClass("Model")
if itemCheck then
print(itemCheck.Name.." was found inside of the Instance!")
local clone = itemCheck:Clone() -- Creates a clone of the model that was found
else
warn("No model was found directly inside of the Instance")
end
It warned “No model was found directly inside of the Instance” BUT, ok printed and everything was working except for this part
I’m not sure when you’re calling this method on that particular Instance but keep in mind there’s the possibility that the model you’re looking for had not yet been added into the model prior to that particular moment.
Additionally, I’m not sure what this is referring to since there’s not enough context.
Im calling this when
PlayerGui:WaitForChild("MainGui").InventoryHolder.Inventory.Duplicates.ChildAdded:Connect(function(child)
Ill give you the full script
local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local InventoryStuff = PlayerGui.MainGui:WaitForChild("InventoryHolder").Inventory.Duplicates
local rep = game:GetService("ReplicatedStorage")
PlayerGui:WaitForChild("MainGui").InventoryHolder.Inventory.Duplicates.ChildAdded:Connect(function(child)
for index,children in pairs(InventoryStuff:GetChildren()) do
if children:IsA("ImageButton") then
print("IS an Imagebutton")
local newchild = children:Clone()
local itemCheck = children.VP:FindFirstChildOfClass("Model")
if itemCheck then
print(itemCheck.Name.." was found inside of the Instance!")
local newArmor = itemCheck:Clone() -- Creates a clone of the model that was found
newArmor.Parent = newchild.VP
else
warn("No model was found directly inside of the Instance")
newchild.Parent = PlayerGui:WaitForChild("MainGui").SellFrame.Duplicates
newchild.Visible = true
print("OK")
newchild.MouseButton1Click:Connect(function()
PlayerGui:WaitForChild("MainGui").SellFrame.Frame.Visible = true
newchild.Name = children.Name
PlayerGui:WaitForChild("MainGui").SellFrame.Frame.Title.Text = "Are you sure you want to sell "..children.ArmorName.Value
end)
PlayerGui:WaitForChild("MainGui").SellFrame.Frame.Sell.MouseButton1Click:Connect(function()
newchild:Destroy()
children:Destroy()
PlayerGui:WaitForChild("MainGui").SellFrame.Frame.Visible = false
end)
PlayerGui:WaitForChild("MainGui").InventoryHolder.Inventory.Duplicates.ChildRemoved:Connect(function(child)
print("Removed")
end)
end
end
end
end)