Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to index nil with 'activated' how to fix?

Asked by 3 years ago
Edited 3 years ago

https://gyazo.com/c682ab0a4b47f6c0c14c4eb6869b2585

^ error code

function ConnectNewMode(Tool)
    local Cooldown = 10
    local StaminaTaken = 0
    local ToggleMode = false
    local LastActivate = tick()-Cooldown
    local EffectMeshes = game:GetService("ServerStorage"):WaitForChild("Effects"):WaitForChild("ModeEffect")

    local function CreateSwirly()
        local Swirly = EffectMeshes:FindFirstChild("Swirl"):Clone()
        local SwirlyMain = EffectMeshes:FindFirstChild("SwirlMain"):Clone()
        Swirly.Parent = workspace.Effects
        Swirly.Color = Stats.EyeColor.Value

        SwirlyMain.Parent = workspace.Effects
        SwirlyMain.Color = Stats.EyeColor.Value

        game.Debris:AddItem(Swirly)
        game.Debris:AddItem(SwirlyMain)

        local Y = math.random(1,360)
        Swirly.CFrame = Character.HumanoidRootPart.CFrame*CFrame.Angles(0,Y,0)*CFrame.new(0,2,0)
        SwirlyMain.CFrame = Character.HumanoidRootPart.CFrame*CFrame.Angles(0,Y,0)*CFrame.new(0,2,0)
        TweenInst(SwirlyMain,TweenInfo.new(1),{Transparency = 1,Size = Vector3.new(SwirlyMain.Size.X+20,SwirlyMain.Size.Y+10,SwirlyMain.Size.Z+20),CFrame = SwirlyMain.CFrame*CFrame.Angles(0,math.rad(180),0)})    
        TweenInst(Swirly,TweenInfo.new(1),{Transparency = 1,Size = Vector3.new(Swirly.Size.X+20,Swirly.Size.Y+10,Swirly.Size.Z+20),CFrame = Swirly.CFrame*CFrame.Angles(0,math.rad(180),0)})
    end


    local function ActivateParticles()
        local Particles = EffectMeshes:FindFirstChild("KureAura"):Clone()
        Particles.Name = Player.Name.."_ModeParticles"
        Particles.Parent = workspace.Effects
        for _,v in pairs(Particles:GetChildren()) do
            if not Character[v.Name] then continue end
            v.CFrame = Character[v.Name].CFrame
            local TempWeld = Instance.new("WeldConstraint", v)
            TempWeld.Part0 = v
            TempWeld.Part1 = Character[v.Name]
        end
    end

    local function DeactivateParticles()
        local Particles = workspace.Effects:FindFirstChild(Player.Name.."_ModeParticles")
        if Particles then
            for _,v in pairs(Particles:GetDescendants()) do
                if v:IsA("ParticleEmitter") then
                    v.Enabled = false
                end
                if v:IsA("PointLight") then v:Destroy() end
            end
        end
        game.Debris:AddItem(Particles, 3)
    end

    local function ActivationEffect()
        local RayParams = RaycastParams.new()
        RayParams.FilterDescendantsInstances = {workspace.Effects,workspace.Live}
        RayParams.FilterType = Enum.RaycastFilterType.Blacklist
        local Ground = workspace:Raycast(Character.HumanoidRootPart.CFrame.p,Vector3.new(0,-20,0),RayParams)

        if Ground ~= nil then
            local Rock = EffectMeshes:FindFirstChild("Rock"):Clone()
            Rock.Name = Player.Name.."_ModeRocks"
            Rock.Parent = workspace.Effects
            Rock.Position = Ground.Position - Vector3.new(0,1.5,0)
            Rock.Material = Ground.Instance.Material
            Rock.Color = Ground.Instance.Color
            Rock.Orientation = Vector3.new(0,math.random(0,360),0)
            Promise.delay(5):andThen(function() TweenInst(Rock, TweenInfo.new(5), {Transparency = 1}) end)
            game.Debris:AddItem(Rock, 10)
            CreateDebris(20,Character.HumanoidRootPart.CFrame*CFrame.new(0,1,0),1)
        end

        local Sound = game.ServerStorage.Sounds.Heartbeat:Clone()
        Sound.PlaybackSpeed = 1.2
        Sound.Parent = Character.HumanoidRootPart
        Sound:Play()

        CreateSwirly()
        ActivateParticles()

    end

    local function ActivateMode() 
        ToggleMode = true
        PlayAnim("Mode",1)
        local Stun = Instance.new("IntValue")
        Stun.Name = "Stun"
        Stun.Parent = Character.Effects

        game.Debris:AddItem(Stun, 0.5)
        Boosts.Speed = Boosts.Speed+35
        Boosts.Damage = Boosts.Damage+35
        Boosts.CombatSpeed = Boosts.CombatSpeed+35
        Boosts.Endurance = Boosts.Endurance+35
        local Int = Instance.new("IntValue",Character.Effects)
        Int.Name = "Mode"
        ActivationEffect()
    end

    local function DeactivateMode()
        ToggleMode = false
        Boosts.Speed = Boosts.Speed-35
        Boosts.Damage = Boosts.Damage-35
        Boosts.CombatSpeed = Boosts.CombatSpeed-35
        Boosts.Endurance = Boosts.Endurance-35
        if Character.Effects:FindFirstChild("Mode") then Character.Effects.Mode:Destroy() end

        local Sound = game.ServerStorage.Sounds.HeavyPunchWoosh:Clone()
        Sound.Parent = Character.HumanoidRootPart
        Sound:Play()
        game.Debris:AddItem(Sound, 3)

        if Character.HumanoidRootPart:FindFirstChild("Heartbeat") then Character.HumanoidRootPart.Heartbeat:Destroy() end
        DeactivateParticles()
    end

    Tool.Activated:Connect(function()
        local CanActivate = math.abs(tick()-LastActivate)
        if CanActivate > Cooldown and CheckActivate() then
            LastActivate = tick()
            ShowCd(Tool, Cooldown)

            if not ToggleMode then
                ActivateMode()
            else
                DeactivateMode()
            end
            Promise.defer(function(resolve, reject)
                while ToggleMode do
                    if Stats.Stamina.Value < StaminaTaken then DeactivateMode() end
                    if StaminaTaken > 0 then Stats.Stamina.Value = Stats.Stamina.Value - StaminaTaken end
                    wait(1)
                end
            end)
        end
    end)    
end

Answer this question