How do i change a part to a model

I want to change the part when it’s going In the machine to a model from replicated storage into the game but how do I do that?

this is my script

local tycoon = script.Parent.Parent.Parent
local processor = script.Parent.Processor
local objectsFolder = tycoon.Objects
local Glass = game.ReplicatedStorage.Glass
local Bottle = game.ReplicatedStorage.Bottle

local function processPart(part)
if part.Name == “CleanGlass” then
part.Name = “GlassBottle”
part.Material = Enum.Material.SmoothPlastic

end

end

local function onTouched(otherPart)
if otherPart.Parent == objectsFolder then
processPart(otherPart)
end
end

processor.Touched:Connect(onTouched)

local tycoon = script.Parent.Parent.Parent
local processor = script.Parent.Processor
local objectsFolder = tycoon.Objects
local Glass = game.ReplicatedStorage.Glass
local Bottle = game.ReplicatedStorage.Bottle

local function processPart(part)
   if part.Name == “CleanGlass” then
      part.Name = “GlassBottle”
      part.Material = Enum.Material.SmoothPlastic
   end
end

local function onTouched(otherPart)
   if otherPart.Parent == objectsFolder then
      processPart(otherPart)
   end
end

processor.Touched:Connect(onTouched)

^ Code block please. I will edit this reply once I read through the code.

local function processPart(part)
   if part.Name == "CleanGlass" then
      local GlassBottle = Glass:Clone()
      GlassBottle.Name = "GlassBottle"
      GlassBottle.Position = part.Position
      GlassBottle.Parent = workspace
   end
end

Something like this may work, however I am not sure about the position part, you may need to use CFrames.

i have a error and it doesnt even work ):

What error are you getting? And where is the script located?

local tycoon = script.Parent.Parent.Parent

local processor = script.Parent.Processor

local objectsFolder = tycoon.Objects

local Glass = game.ReplicatedStorage.Glass

local Bottle = game.ReplicatedStorage.Bottle

local function processPart(part)

if part.Name == “CleanGlass” then

part.Name = “Bottle”

part.Material = Enum.Material.SmoothPlastic

end

end

local function onTouched(otherPart)

if otherPart.Parent == objectsFolder then

processPart(otherPart)

end

end

processor.Touched:Connect(onTouched)

I just made it a code block so that others can read it, I have added a following edit that may work. To code block please use ```lua at the start and at the end ```

1 Like

how do I take a screenshot of my entire workspace

i have a part called proccesor part in the cutting machine when the part goes in the object it should change into the bottle model in replicated storage

it clones the same part againrobloxapp-20210330-2129122.wmv (2.7 MB)

Make sure to destroy it. So in the ProcessPart function add part:Destroy()