I'm remaking a gun system I made a while ago, and I'm optimizing it as much as possible. I'm trying to add particle effects based on material. Here's the function I made:
function CalculateTexture(Hit)
local Prefix = "rbxasset://"
local ReturnThis = Prefix..Particle.Fabric
if Hit.Material == Enum.Material.Brick or
Hit.Material == Enum.Material.Cobblestone or
Hit.Material == Enum.Material.Concrete or
Hit.Material == Enum.Material.Granite or
Hit.Material == Enum.Material.Marble or
Hit.Material == Enum.Material.Pebble or
Hit.Material == Enum.Material.Slate then
ReturnThis = Prefix..Particle.Concrete
elseif Hit.Material == Enum.Material.Grass then
ReturnThis = Prefix..Particle.Grass
elseif Hit.Material == Enum.Material.CorrodedMetal or
Hit.Material == Enum.Material.DiamondPlate or
Hit.Material == Enum.Material.Foil or
Hit.Material == Enum.Material.Metal then
ReturnThis = Prefix..Particle.Metal
elseif Hit.Material == Enum.Material.Sand or
Hit.Material == Enum.Material.Plastic or
Hit.Material == Enum.Material.SmoothPlastic or
Hit.Material == Enum.Material.Neon then
ReturnThis = Prefix..Particle.Sand
elseif Hit.Material == Enum.Material.Wood or
Hit.Material == Enum.Material.WoodPlanks then
ReturnThis = Prefix..Particle.Wood
end
return ReturnThis
end
It simply just figures out what material it is and returns the texture based on material... Is there any simpler way to do this? I want it to be as optimized as possible, meaning this large function may simply not do...

4 comments
You could try to mimic a switch http://lua-users.org/wiki/SwitchStatement
That link is awesome ^
It worked pretty well. Unfortunately, it made the script longer. I may just stick to one texture instead
It should be able to make the function smaller. It might add some tables outside of the function... But Good Luck man!