I have this code below that spawns in a new part that has a specific value (cash) but how can I change that part into a mesh? The part spawn location is .SpawnPart
local DropperPartsFolder = script.Parent.Parent.Parent.DropperParts
while wait(2) do
local NewPart = Instance.new("Part",DropperPartsFolder)
NewPart.Position = script.Parent.SpawnPart.Position
NewPart.Size = Vector3.new(1,1,1)
local CashValue = Instance.new("NumberValue",NewPart)
CashValue.Value = 1
CashValue.Name = "CashValue"
end
Instead of using Instance.new, it would be easier to put your precreated drops into ServerStorage, and then clone them so you can customize them all you want.
You need to create a new mesh inside of the part, here’s how.
local DropperPartsFolder = script.Parent.Parent.Parent.DropperParts
while wait(2) do
local NewPart = Instance.new("Part",DropperPartsFolder)
NewPart.Position = script.Parent.SpawnPart.Position
NewPart.Size = Vector3.new(1,1,1)
local mesh = Instance.new("SpecialMesh", NewPart)
mesh.MeshType = Enum.MeshType.FileMesh
mesh.TextureId = "" -- set to TextureId
mesh.MeshId = "" -- set to MeshId
local CashValue = Instance.new("NumberValue",NewPart)
CashValue.Value = 1
CashValue.Name = "CashValue"
end
Step 1: Create a MeshPart in studio and upload the desired mesh.
Step 2: Keep the part somewhere in storage (below script does it on ReplicatedStorage)
Step 3: Clone that part from storage and drop it
Here is an example below:
Note: Change the “MyMeshPartName” reference to your mesh name on the desiredMeshPart variable
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DropperPartsFolder = script.Parent.Parent.Parent.DropperParts
local desiredMeshPart = ReplicatedStorage.MyMeshPartName
while task.wait(2) do
local NewPart = desiredMeshPart :Clone()
NewPart.Parent = DropperPartsFolder
NewPart.Position = script.Parent.SpawnPart.Position
--NewPart.Anchored = false -- uncomment if your mesh part is anchored
--NewPart.Size = Vector3.new(1,1,1)
local CashValue = Instance.new("NumberValue",NewPart)
CashValue.Value = 1
CashValue.Name = "CashValue"
end
Maybe try removing “mesh.MeshType = Enum.MeshType.FileMesh”. I’m not sure why the mesh does not work, you could also try cloning a mesh you already have from something such as the serverstorage, lighting, replicated storage, etc.
The problem I am currently having is the collector is not destroying the meshes.
local CashValue = script.Parent.Parent.Parent.Parent.Values.CashValue
script.Parent.Touched:Connect(function(Hit)
if Hit.Name == "RobloxVisor2007" and Hit:FindFirstChild("CashValue") then
CashValue.Value += Hit:FindFirstChild("CashValue").Value
Hit:Destroy()
end
end)
Currently getting this error Workspace.TycoonModel.Boughtitems.FirstDropper.Script:14: attempt to call a Instance value
from this:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DropperPartsFolder = script.Parent.Parent.Parent.DropperParts
local desiredMeshPart = ReplicatedStorage.RobloxVisor2007
while task.wait(2) do
local NewPart = desiredMeshPart :Clone()
NewPart.Parent = DropperPartsFolder
NewPart.Position = script.Parent.SpawnPart.Position
--NewPart.Anchored = false -- uncomment if your mesh part is anchored
--NewPart.Size = Vector3.new(1,1,1)
local CashValue = NewPart("NumberValue",NewPart)
CashValue.Value = 1
CashValue.Name = "CashValue"
end
local DropPart = game.ReplicatedStorage.DuckDrop
while true do
local drop = DropPart:Clone()
drop:SetAttribute("Money",10) --set each drop to 10 value
drop:PivotTo(script.Parent.CFrame)
drop.PrimaryPart.Anchored = false
local color = BrickColor.random()
drop.Duck1.BrickColor = color
drop.Duck2.BrickColor = color
drop.Duck1.Transparency = 0
game.Debris:AddItem(drop,5)
drop.Parent = workspace
task.wait(1)
end
script.Parent.Touched:Connect(function(hit)
if hit and hit.Parent and hit.Parent.Name == "DuckDrop" then
local drop = hit.Parent
if drop.Duck1.Transparency == 0 then
drop:SetAttribute("Money",drop:GetAttribute("Money")*2) --double the value
drop.Duck1.Transparency = 1
drop.Duck2.Transparency = 0
end
end
end)