What is best way to handle various VFX effects?

Hello, i’m currently working on a game where you mine rocks, i plan to add some VFX to it, for now i have module with functions, for instance GuiVFX.levelUp or GuiVFX.itemCollection, but i don’t think it’s good methood that can be expanded later to handle new mechanics, is there any better and simple way to handle them?

1 Like

if the script that handles LevelingUp/CollectingItems is a module script then you can use signals to fire them whenever the player collects something and when they are fired the Vfx Module will handle them

local VFX = {}
local Signal = require("Path To Functionality Module Script")

-- storing these functions in tables is more organized (in my opinion)
VFX.Functions = {
	["LevelUp"] = function()
		 -- level up logic
	end,
	["ItemCollection"] = function()
		-- ItemCollection up logic
	end,
}

-- events that get fired whenever the player levelup/collect Item/etc
Signal.OnLevelUp:Connect(function()
	VFX.Functions.LevelUp()
end)
Signal.OnItemCollection:Connect(function()
	VFX.Functions.ItemCollection()
end)

--//// or this
-- an event that fire Up to Trigger Vfx with the name of the vfx to trigger being the same name in the Vfx.Functions table
Signal.TriggerVfx:Connect(function(vfxToTrigger : "LevelUp" | "ItemCollection")
	VFX.Functions[vfxToTrigger]()
end)

return VFX

or you can not use signals and call the functions from your main script

local VFX = require(VFX)

when player level up do
	VFX.Functions.LevelUp()
end

when player Collect an do
	VFX.Functions.ItemCollection()
end
2 Likes

Isn’t this hardcoding in this case? i use almost the same methood for now, i call VFX.levelUp() and pass data, i don’t think it’s good aproach

2 Likes

well, you will need to let the script know when to do VFX and since every action have a different VFX then you will need to specify what VFX function to trigger

2 Likes

Remotes take care of this, for instance when Level value changes the function fires, i pretty much didn’t think about that simple solution, thx for help

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.