Optional backstory, skip if you don't care.
So around 8 months ago I saw some footage of Arcane Odyssey and there was a cool system where the materials switched whenever there’s heavy rain in the area. The problem with that game’s implementation is that the default materials are getting changed, which causes a noticeable lag spike since the method used is equivalent to iterating through all of workspace and changing the materials from there. I just remembered that a little bit ago and one hour later, we’re here.
Rain Material Swapper:
Hello! My name is Kep and this is a cool little system I made in an hour. In short, you can update the materials of parts in an area to variants that look wet or shiny to further improve your rain effects!
Here’s an example of how it works:
I move around in the video to show how there are no lag spikes. This free model has 1200 parts, and there are no spikes since only X amount of parts are changed per frame. I’ve stress tested it with 24000 parts, and I got the same results, no lag spikes.
Module Download:
RainMaterialSwapper.rbxm (1.8 KB)
Here’s how to use it:
--[[
DISCLAIMER!!!
Please use this module with a LOCAL SCRIPT.
The changes are purely visual.
]]--
local RainMatSwapper = require(Pathway:WaitForChild("RainMaterialSwapper"))
local AreaName = "ExampleArea"
RainMatSwapper:toggleRain(RainMatSwapper.Areas[AreaName],true)
Additional Setup:
Have a folder where you keep all your rain material variants and make sure they all have a common prefix/suffix.
Have a folder where you keep all the areas inside of workspace.
You will have to edit the module to get it working with your game, so beginner-intermediate scripting knowledge is required. There are comments in the module nearby the things that need to be changed, so it shouldn’t be too difficult. As an example of how you could modify the system, I have it merged with my project’s map loading/unloading system.
Credit me if you want, but I don’t really care if you do or not. Let me know any feedback or issues you may have!