Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I Can't Get My Custom Meshes to Spawn?

So I'm brand new to LUA coding and Roblox Studio (though I'm familiar with coding in general). I have successfully created and imported my own custom mesh with a texture, a simple apple.

However, I wanted to mess with scripting and attempted to add in a tycoon-style dropper with a button that would drop the apples when you clicked it. After having zero luck getting it to work, I scrapped the dropper and decided on "Click the button and an apple will fall from the sky".

I successfully got a ball to fall from the sky using this code:

function onClicked(playerWhoClicked)
	script.Parent.Transparency=1
	wait(.1)
	script.Parent.Transparency=0
local sphere = Instance.new("Part") -- creates a part
        sphere.Shape = Enum.PartType.Ball -- sets the part shape to a ball
        sphere.Position = Vector3.new(15,20,10) -- replace x,y,z with where you'd like the ball to spawn
        sphere.Parent = workspace -- this sets the Parent of the part to the workspace
    end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

But after reading and reading about Welding, SpecialMesh, Cloning, CFrames, I. Can. Not. get my apple to spawn. When I click the button, nothing happens.

Here's the mess I currently have right now. Some things I've tried are commented out. You can see that my mesh's ID is rbxassetid://4562211818. The name is "Apple".

function onClicked(playerWhoClicked)
	script.Parent.Transparency=1
	--Put commands here
	wait(.1)
	script.Parent.Transparency=0
	--If you want the command to activate after the 
	--button is pressed, put the commands here instead.
	
	--local mesh = Instance.new("SpecialMesh",part) --makes mesh like you make a part
	--mesh.MeshType = Enum.MeshType.FileMesh
    --mesh.MeshID = "rbxassetid://4562211818" --id of mesh
	--local clonedobject = mesh:Clone()
	local part = Instance.new("Part",workspace.PartStorage)
	           part.BrickColor= game.Workspace.DropColor.Value
	           part.Material=game.Workspace.MaterialValue.Value
	           local mesh = Instance.new("SpecialMesh")
	           mesh.Parent = part
	           mesh.MeshType = "FileMesh"
	           mesh.MeshId = "rbxassetid://4562211818"
			mesh:SetPrimaryPartCFrame(CFrame.new(15,10,10))
			--mesh.Position = Vector3.new(15,50,10)
	
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

I just need someone to explain to me how to make this happen as straightforwardly as possible, ideally with explanations of what is supposed to go where and what it does so I can work with this more in the future. I don't get it at all.

I'd like to make my own worlds in the future and use a lot of, if not mostly, my own custom models, so I need to learn how to work with them.

1 answer

✓ Accepted answer

I think it was erroring because part.BrickColor= game.Workspace.DropColor.Value DropColor was most likely a string since there's no brickcolor in value objects

Also, part.Material=game.Workspace.MaterialValue.Value material should be an enum and there's no way to have enums in value objects

This will cause the script to error.

We went over it on discord and came up with the solution.

All you need is a brick with a click detector and script inside the part for this to work.

function onClicked(playerWhoClicked)
    --'flashes' transparency of brick to indicate that the brick was clicked
    script.Parent.Transparency=1
    wait(.1)
    script.Parent.Transparency = 0

    --creates a new part and put's it in the workspace
    local part = Instance.new("Part")
    part.Parent = workspace
    
    --puts mesh onto part
    local mesh = Instance.new("SpecialMesh")
    mesh.Parent = part
    mesh.MeshType = "FileMesh"
    
    mesh.MeshId = "rbxassetid://4562211818"--adds a mesh to the special mesh
    mesh.TextureId = "rbxassetid://4562295617" --adds a texture to the mesh
    mesh.Scale = Vector3.new(.1,.1,.1) -- changes the size of the mesh
        
    part.Position = Vector3.new(15,10,10) --puts the apple at the position 15,10,10

	wait(1)
	part:Destroy()
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

This discussion is preserved as it was. New answers, comments, and votes are closed.