Error with my swep

I’m using this to for slowness in my swep.


function EFFECT:Init( data )
    
    self.Position = data:GetOrigin()    

    local emitter = ParticleEmitter( self.Position )
    local emittersed = ParticleEmitter( self.Position )
    local RanParticle = math.random( 1, 3)


        for i=1, 10 do    

        if RanParticle == 1 then

        
            local particle = emitter:Add( "effects/flake1", self.Position + Vector(0, 0,math.random(30,60)) )

                particle:SetVelocity(Vector(math.random(-20,20),math.random(-20,20), math.random(-20, 0)))
                particle:SetDieTime(math.Rand( 2, 3 ))
                particle:SetStartAlpha(230)
                particle:SetEndAlpha(0)
                particle:SetStartSize(math.random(1, 5))
                particle:SetEndSize( 0 )
                particle:SetRoll( math.Rand( 0,10  ) )
                particle:SetRollDelta(math.Rand( -0.2, 0.2 ))
                particle:SetColor( math.Rand(200, 255), math.Rand(200, 255), 255 )
                particle:VelocityDecay( false )
        end        


But I get this error in Gmod:
[lua\weapons\sample\shared.lua:90] ‘end’ expected (to close ‘for’ at line 73) near ‘<eof>’

What does it mean and what should I do about it?


function EFFECT:Init( data )
    
    self.Position = data:GetOrigin()    

    local emitter = ParticleEmitter( self.Position )
    local emittersed = ParticleEmitter( self.Position )
    local RanParticle = math.random( 1, 3)


        for i=1, 10 do    

        if RanParticle == 1 then

        
            local particle = emitter:Add( "effects/flake1", self.Position + Vector(0, 0,math.random(30,60)) )

                particle:SetVelocity(Vector(math.random(-20,20),math.random(-20,20), math.random(-20, 0)))
                particle:SetDieTime(math.Rand( 2, 3 ))
                particle:SetStartAlpha(230)
                particle:SetEndAlpha(0)
                particle:SetStartSize(math.random(1, 5))
                particle:SetEndSize( 0 )
                particle:SetRoll( math.Rand( 0,10  ) )
                particle:SetRollDelta(math.Rand( -0.2, 0.2 ))
                particle:SetColor( math.Rand(200, 255), math.Rand(200, 255), 255 )
                particle:VelocityDecay( false )
        end
        end
end


That should solve it.

Means that you didn’t close the for loop.

Thanks a ton, I’m pretty new at this. Sorry to have so many questions, but now it says:

[lua\weapons\sample\shared.lua:64] attempt to index global ‘EFFECT’ (a nil value)

Haha, np, everyone has to start somewhere :slight_smile:
Ummm, then I think you’ll need to create a new effect, since it’s a swep, not an effect x) (e.g. create a init.lua in lua\effects&lt;name-of-effect>\ and do some coding).
I’m not good when it comes to particles/effects, however you could check out the Garry’s Mod wiki and the backup on the old one on http://maurits.tv/data/garrysmod/. Or maybe luasearch.
Though, atm the maurits one is offline and cloudflare doesn’t seem to help much, and I’m not on my desktop comp atm, if I was, I would be able to help more since I have all my lua-related things on there.

Create an EFFECT table at the top


local EFFECT = {}

Then register the effect and use it somewhere.


effects.Register(EFFECT,"name_of_effect")

Like this?


function EFFECT:Init( data )
	local EFFECT: = {}
    self.Position = data:GetOrigin()    
	effects.Register(EFFECT,"slow")
    local emitter = ParticleEmitter( self.Position )
    local emittersed = ParticleEmitter( self.Position )
    local RanParticle = math.random( 1, 3)


        for i=1, 10 do    

        if RanParticle == 1 then

        
            local particle = emitter:Add( "effects/flake1", self.Position + Vector(0, 0,math.random(30,60)) )

                particle:SetVelocity(Vector(math.random(-20,20),math.random(-20,20), math.random(-20, 0)))
                particle:SetDieTime(math.Rand( 2, 3 ))
                particle:SetStartAlpha(230)
                particle:SetEndAlpha(0)
                particle:SetStartSize(math.random(1, 5))
                particle:SetEndSize( 0 )
                particle:SetRoll( math.Rand( 0,10  ) )
                particle:SetRollDelta(math.Rand( -0.2, 0.2 ))
                particle:SetColor( math.Rand(200, 255), math.Rand(200, 255), 255 )
                particle:VelocityDecay( false )
        end
        end
end

No, he meant like this.
[lua]
local EFFECT = {}

function EFFECT:Init( data )
self.Position = data:GetOrigin()
local emitter = ParticleEmitter( self.Position )
local emittersed = ParticleEmitter( self.Position )
local RanParticle = math.random( 1, 3)

    for i=1, 10 do    

    if RanParticle == 1 then

    
        local particle = emitter:Add( "effects/flake1", self.Position + Vector(0, 0,math.random(30,60)) )

            particle:SetVelocity(Vector(math.random(-20,20),math.random(-20,20), math.random(-20, 0)))
            particle:SetDieTime(math.Rand( 2, 3 ))
            particle:SetStartAlpha(230)
            particle:SetEndAlpha(0)
            particle:SetStartSize(math.random(1, 5))
            particle:SetEndSize( 0 )
            particle:SetRoll( math.Rand( 0,10  ) )
            particle:SetRollDelta(math.Rand( -0.2, 0.2 ))
            particle:SetColor( math.Rand(200, 255), math.Rand(200, 255), 255 )
            particle:VelocityDecay( false )
    end
    end

end
effects.Register(EFFECT,“slow”)[/lua]

Now I get this error :confused:

[lua\weapons\sample\shared.lua:94] attempt to index global ‘effects’ (a nil value)

Sorry if these are noobish questions, I’m not good at this.

You can’t reload a swep’s files with lua_openscript or lua_openscript_cl if you are trying to reload the swep just restart the map.