Cloning a part based on a StringValue

Hey! I’m making a survival game and since I’m not a great scripter, there is some stuff that I’m doing inefficiently so let me know if there is anything I should change. Anyway, I am gonna give an example of my question.

Let’s say an axe breaks a tree. In the tree’s model, there is a value called “Drop”. The value is a StringValue and the value is “Oak Log”. I want to clone an Oak Log that is located in ReplicatedStorage using the StringValue. Is there any way to do this? I will happily provide my code if necessary. Thanks!

I think this is what you might want to do:

local StringValue = -- The string value here
local ReplicatedStorage = game:GetService("ReplicatedStorage")
if ReplicatedStorage:FindFirstChild(StringValue.Value) then
   local ObjectGot = ReplicatedStorage:FindFirstChild(StringValue.Value):Clone()
   ObjectGot.Parent = workspace
end
1 Like

Exactly what I needed. Thanks!!

1 Like