PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

Visible

ForceField

bool

Determines whether or not the ForceField's particle effect is visible.

When is set to true, a particle effect is created, a number of rules determine where this effect will be emitted from.

When parented to a Model, if the model includes a Humanoid named “Humanoiod” with Humanoid/RigType set to R15, the effect will be emitted from the part named “UpperTorso”. Otherwise, the effect will be emitted from the part named “Torso”. The part must have the same parent as the ForceField, if it does not exist then the effect is emitted at 0, 0, 0.

When parented to a BasePart the effect will be emitted from the part’s BasePart/Position.

One use for this property is replacing the default particle effect with a custom effect using ParticleEmitters.


Code Samples


Custom ForceField Effect

This sample includes a function that will replace the default ForceField particle effect with an effect using ParticleEmitters that can be modified by the developer.

local Debris = game:GetService("Debris")

local function createCustomForcefield(player, duration)
	local character = player.Character
	if character then
		local humanoid = character:FindFirstChild("Humanoid")
		if humanoid then
			-- find the torso
			local torsoName = humanoid.RigType == Enum.HumanoidRigType.R15 and "UpperTorso" or "Torso"
			local torso = character:FindFirstChild(torsoName)
			if torso then
				-- create a forcefield
				local forceField = Instance.new("ForceField")
				forceField.Visible = false -- not visible
				-- create a particle effect
				local particleEmitter = Instance.new("ParticleEmitter")
				particleEmitter.Enabled = true 
				particleEmitter.Parent = torso
				-- listen for the forcefield being removed
				forceField.AncestryChanged:Connect(function(child, parent)
					if not parent then
						if particleEmitter and particleEmitter.Parent then
							particleEmitter:Destroy()
						end	
					end
				end)
				-- parent the forcefield and set it to expire
				forceField.Parent = character
				if duration then
					Debris:AddItem(forceField, duration)
				end
			end
		end
	end
end