Vfx is a specialized type of SmartObject for visual effects. It inherits everything from SmartObject.
|Function Name||Return Type||Description||Tags|
| || ||Starts playing the effect. The ||None|
| || ||Stops playing the effect. The ||None|
In this example, a script is placed as a child of a Visual Effect object (e.g. Spark Explosion VFX). The
Play() function is called periodically, with a random delay between 2 and 4 seconds. VFXs work best when they are under a client context.
local VFX = script.parent local MIN_DELAY = 2 local MAX_DELAY = 4 while true do local delay = math.random(MIN_DELAY, MAX_DELAY) Task.Wait(delay) VFX:Play() end
In this example, a script detects when players enter and exit a trigger. If there are any players in the trigger, a looping visual effect is played (e.g. Fire Volume VFX). Once all players have left the trigger the VFX stops playing. The
Stop() function is also called in the very beginning in case the VFX comes with "Auto Play" enabled and we are assuming no players begin inside the trigger.
local VFX = script.parent local TRIGGER = script:GetCustomProperty("Trigger"):WaitForObject() VFX:Stop() local playerCount = 0 function OnBeginOverlap(trigger, other) if other:IsA("Player") then playerCount = playerCount + 1 if playerCount == 1 then VFX:Play() end end end function OnEndOverlap(trigger, other) if other:IsA("Player") then playerCount = playerCount - 1 if playerCount == 0 then VFX:Stop() end end end TRIGGER.beginOverlapEvent:Connect(OnBeginOverlap) TRIGGER.endOverlapEvent:Connect(OnEndOverlap)