Help with function

I need help with my function. It is spawning normal bricks every time and I can’t seem to solve the issue. How could I fix the code?

local RNG = math.random(1,4)


function PartSpawner (PartName)
	local PartName = Instance.new("Part")
	PartName.Parent = workspace
	PartName.Shape = Enum.PartType.PartName
end

if RNG == 1 then
	PartSpawner(Block)
	
elseif RNG == 2 then
	PartSpawner(Wedge)
	
elseif RNG == 3 then
	PartSpawner(Ball)
	
elseif RNG == 4 then
	PartSpawner(Cylinder)
	
end

Switch the names. Try to not make different variables the same name :pray:

Anyway here:

function PartSpawner (PartType)
	local PartName = Instance.new("Part")
	PartName.Parent = workspace
	PartName.Shape = Enum.PartType[PartType]
end

PartSpawner("Ball") --You have to use a string

You are trying to set the part to be of the type “PartName”, NOT whatever the value of PartName is.

You can either do what the person above did, OR you can just do

PartName.Shape = PartType

Roblox should convert the string into the relevent enum

Here, did a bit of improvements on your code!
hope this helps : )

local RNG = math.random(1,4)

local PartTypes = {
	[1] = Enum.PartType.Block,
	[2] = Enum.PartType.Wedge,
	[3] = Enum.PartType.Ball,
	[4] = Enum.PartType.Cylinder,
}

function PartSpawner(enum : Enum)
	local PartName = Instance.new("Part")
	PartName.Parent = workspace
	PartName.Shape = enum
end

PartSpawner(PartTypes[RNG])