Im not sure why this happens, but when i try to make another particle function it spits out:

 16:06:55.391 - ReplicatedStorage.CustomMovement.Particles:171: attempt to index nil with 'Enabled'
16:06:55.392 - Stack Begin
16:06:55.392 - Script 'ReplicatedStorage.CustomMovement.Particles', Line 171 - function airPuff
16:06:55.393 - Script 'ReplicatedStorage.CustomMovement.MoveSet', Line 290 - function highJump
16:06:55.393 - Script 'ReplicatedStorage.CustomMovement.MoveSet', Line 434 - function onJumpRequest
16:06:55.394 - Script 'Workspace.hasanchik.MainControl', Line 77
16:06:55.394 - Stack End

The first particle function works fine.

function particles:airPuff()
	local self = particles:getSelf()
	local puffPart = self.airPuffPart
	local particle = self.airPuffParticle
	particle.Enabled = true
	
	delay(0.3, function()
		particle.Enabled = false
	end)

	if (RUNSERVICE:IsClient()) then
		jumpParticleEvent:FireServer()
	end
end

The second one

function particles:highJumpParticleFunc()
	local self = particles:getSelf()
	local puffPart = self.highJumpPart
	local particle = self.highJumpParticle
	particle.Enabled = true

	delay(0.3, function()
		particle.Enabled = false
	end)

	if (RUNSERVICE:IsClient()) then
		jumpParticleEvent:FireServer()
	end
end

errors out with attempt to index nil with 'Enabled'.

I tried printing the "self.airPuffParticle" but it just printed the name.

Then i tried printing "self.highJumpParticle" IN the second function, but somehow it returned nil.

When i tried printing "self.highJumpParticle" in the particles.new function it worked fine. It did NOT print nil.

Can you help on this? Thanks. Full script:

local core = script.Parent
local remotes = core:WaitForChild("Remotes")
local particleStorage = core:WaitForChild("ParticleStorage")

local initParticles = remotes:WaitForChild("initParticles")
local setParticleEnabledEvent = remotes:WaitForChild("setParticleEnabled")
local airPuffEvent = remotes:WaitForChild("airPuff")
local jumpParticleEvent = remotes:WaitForChild("jumpParticle")

--

local RUNSERVICE = game:GetService("RunService")

local PART = Instance.new("Part")
PART.Transparency = 1
PART.CanCollide = false
PART.Name = "Particle Part"

local PART2 = Instance.new("Part")
PART2.Transparency = 1
PART2.CanCollide = false
PART2.Size = Vector3.new(0.05, 0.05, 0.05)
PART2.Name = "Tiny Particle Part"

--

local function initTrail(parent)
	local attach0 = Instance.new("Attachment")
	attach0.Name = "Trail0"
	attach0.CFrame = CFrame.new(0, 0, 0)
	attach0.Parent = parent
	
	local attach1 = Instance.new("Attachment")
	attach1.Name = "Trail1"
	attach1.CFrame = CFrame.new(0, parent.Size.y/2, 0)
	attach1.Parent = parent
	
	local trail = particleStorage:WaitForChild("AirTrail"):Clone()
	trail.Name = "AirTrail"
	trail.Attachment0 = attach0
	trail.Attachment1 = attach1
	trail.Parent = parent
	
	return trail
end

local function initFloorParticle(self)
	local accesory = Instance.new("Accessory") -- massless
	accesory.Name = "FloorAccessory"
	accesory.Parent = self.character
	
	local floorPart = PART:Clone()
	floorPart.Name = "FloorParticlePart"
	floorPart.Size = Vector3.new(2, 1, 1)
	floorPart.Parent = accesory
	
	local weld = Instance.new("Motor6D")
	weld.C0 = CFrame.new(0, -self.humanoid.HipHeight - self.hrp.Size.y/2 + 0.5, 0)
	weld.Part0 = self.hrp
	weld.Part1 = floorPart
	weld.Parent = floorPart
	
	local floorParticle = particleStorage:WaitForChild("FloorParticle"):Clone()
	floorParticle.Name = "FloorParticle"
	floorParticle.Parent = floorPart
	
	return floorParticle
end

local function initPuffParticle(self)
	local accesory = Instance.new("Accessory") -- massless
	accesory.Name = "PuffAccessory"
	accesory.Parent = self.character
	
	local puffPart = PART:Clone()
	puffPart.Name = "AirPuffPart"
	puffPart.Size = Vector3.new(4, 2, 4)
	puffPart.Anchored = false
	puffPart.Parent = accesory
	
	local particle = particleStorage:WaitForChild("AirPuffParticle"):Clone()
	particle.Name = "AirPuffParticle"
	particle.Enabled = false
	particle.Parent = puffPart
	
	local weld = Instance.new("Weld")
	weld.C0 = CFrame.new(0, -self.humanoid.HipHeight, 0)
	weld.Part0 = self.upperTorso
	weld.Part1 = puffPart
	weld.Parent = puffPart

	return puffPart
end

local function initHighJumpParticle(self)
	local accesory = Instance.new("Accessory") -- massless
	accesory.Name = "JumpAccessory"
	accesory.Parent = self.character

	local jumpPart = PART2:Clone()
	jumpPart.Name = "JumpParticlePart"
	jumpPart.Size = Vector3.new(4, 2, 4)
	jumpPart.Anchored = false
	jumpPart.Parent = accesory

	local particle = particleStorage:WaitForChild("HighJumpParticle"):Clone()
	particle.Name = "HighJumpParticle"
	particle.Enabled = false
	particle.Parent = jumpPart

	local weld = Instance.new("Weld")
	weld.C0 = CFrame.new(0, -self.humanoid.HipHeight, 0)
	weld.Part0 = self.upperTorso
	weld.Part1 = jumpPart
	weld.Parent = jumpPart

	return jumpPart
end


--

local particles = {}
local particles_mt = {__index = particles}

function particles.new(player)
	self = {}
	
	if (RUNSERVICE:IsClient()) then
		initParticles:InvokeServer()
	end
	
	self.character = player.Character
	self.humanoid = self.character:WaitForChild("Humanoid")
	self.hrp = self.character:WaitForChild("HumanoidRootPart")
	self.upperTorso = self.character:WaitForChild("UpperTorso")
	
	--
	
	self.airTrail = self.upperTorso:FindFirstChild("AirTrail") or initTrail(self.upperTorso)
	self.floorParticle = self.character:FindFirstChild("FloorParticle", true) or initFloorParticle(self)
	
	self.airPuffPart = self.character:FindFirstChild("AirPuffPart", true) or initPuffParticle(self)
	self.airPuffParticle = self.airPuffPart:WaitForChild("AirPuffParticle")
	
	self.highJumpPart = self.character:FindFirstChild("JumpParticlePart", true) or initHighJumpParticle(self)
	self.highJumpParticle = self.highJumpPart:WaitForChild("HighJumpParticle")
	
	return setmetatable(self, particles_mt)
end

--

function particles:setParticleEnabled(key, bool)
	if (self[key].Enabled ~= bool) then
		self[key].Enabled = bool
		if (RUNSERVICE:IsClient()) then
			setParticleEnabledEvent:FireServer(key, bool)
		end
	end
end

function particles:airPuff()
	local self = particles:getSelf()
	local puffPart = self.airPuffPart
	local particle = self.airPuffParticle
	particle.Enabled = true
	
	delay(0.3, function()
		particle.Enabled = false
	end)

	if (RUNSERVICE:IsClient()) then
		jumpParticleEvent:FireServer()
	end
end

function particles:highJumpParticleFunc()
	local self = particles:getSelf()
	local puffPart = self.highJumpPart
	local particle = self.highJumpParticle
	particle.Enabled = true

	delay(0.3, function()
		particle.Enabled = false
	end)

	if (RUNSERVICE:IsClient()) then
		jumpParticleEvent:FireServer()
	end
end

-- 

return particles

(And yes this is egmooses controller, i tried adding sound and more moves ect. to it.)

Thanks!

EDIT: This also happened in another script, where it would error something similair. Its really weird.

2 comments

0

You must run particle.new() before trying to get particle.highJumpParticle

0

i did